You are here: Re: time to int function. « All PHP « IT news, forums, messages
Re: time to int function.

Posted by PSI_Orion on 07/19/06 16:26

The issue I have is that I need to pass something like "1:50" as the
$timeVar variable.

Here's what I have...

function timeToInt($timeVar)
{
echo "alert('$timeVar')";
// sscanf($timeVar,"%d:%d",$hours,$minutes);
// $intVar = ($hours * 60) + $minutes;
// return($intVar);
// echo "alert('$intVar')";
}

and the call is on an onblur in an inpout text field as such...

<input type="text" onblur="<?=timeToInt('1:50')?>">

I have just put "1:50" as an example as this is the format I need to pass to
the function.

If I leave the function as shown above with all the comments I get the
initial echoed alert. As soon as I remove the comment from the second line
(sscanf) the function fails and I don't get any echoed alert.

Am I using the sscanf correctly?

Thanks for your help in this.

PSI_Orion

"Hans 'pritaeas' Pollaerts" <pritaeas@hotmail.com> wrote in message
news:e9livn$inf$1@news2.zwoll1.ov.home.nl...
> Error: line 1 must be:
>
> $time = date ("H:i", time ());
>
> Here's a more complete test:
>
> <?php
> function getMinutes ($time) {
> $time = date ("H:i", $time);
> sscanf ($time, "%d:%d", $hours, $minutes);
> return ($hours * 60) + $minutes;
> }
>
> $time = mktime (1, 30);
> echo $time;
> echo "<br>";
> echo date ("H:i", $time);
> echo "<br>";
> echo getMinutes ($time);
> ?>
>
>
> "Hans 'pritaeas' Pollaerts" <pritaeas@hotmail.com> wrote in message
> news:e9li0g$r8n$1@news6.zwoll1.ov.home.nl...
>> Try this, you can create a function from it:
>>
>> <?php
>> $time = date ("H:m", time ());
>> echo $time . " => ";
>> sscanf ($time, "%d:%d", $hours, $minutes);
>> echo ($hours * 60) + $minutes . " minutes";
>> ?>
>>
>> "PSI_Orion" <orion@psiss.com> wrote in message
>> news:WXpvg.494$t4.298@newsfe3-win.ntli.net...
>> > Is there a simple function that returns HH:MM to an actual integer? In
>> > other words, would convert 1:30 to 90, 2:00 to 120, 4:00 to 240, 1:56
>> > to
>> 116
>> > etc. or is this something you have to create a function for?
>> >
>> > I've looked at all the date and time functions but for the life of me,
>> > I
>> > can't find which one it is I need to use.
>> >
>> > Regards
>> >
>> > PSI_Orion
>> >
>> >
>>
>>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация