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 21:24

OK, I now have the function working correctly and is simply like this...

<?
function timeToInt($timeVar)
{
$timeVar = strtotime($timeVar);
$minutes = ((idate('H',$timeVar) * 60) + idate('i',$timeVar));
return($minutes);
}
?>

But now I've run into a different snag. The snag I have now is how do I
pass the value of a form field to php without reloading the page? In other
words, how can I mix javascript and php?

What I have is this...

<input type="text" name="duration" value="<?=$duration?>"
onblur="duration_mins.value=<?=timeToInt('?>this.value<?');?>">

duration_mins is another text type form field which needs to show the
minutes that correspond to the HH:MM format in the "duration" field shown
above.

If I hard code the value like this...

<input type="text" name="duration" value="<?=$duration?>"
onblur="duration_mins.value=<?=timeToInt('5:50');?>">

It works fine, but when I do it as I need to, in otherwords to change the
duration_mins value to reflect the duration value, it doesn't even finish
the output of the form. I'm not even sure if you can mix and match
javascript and php in a single function call. If I recall isn't javascript
client side and php server side or shouldn't that make any difference?

Regards and thanks for the help to date.

PSI_Orion

"Hans 'pritaeas' Pollaerts" <pritaeas@hotmail.com> wrote in message
news:e9lov2$tbn$1@news2.zwoll1.ov.home.nl...
> function timeToInt($timeVar)
> {
> echo "alert('$timeVar')";
> sscanf($timeVar,"%d:%d",$hours,$minutes);
> // echo "alert('$timeVar')"; // <-- this will fail because sscanf
> messes
> with timevar
> echo "alert('$minutes')";
> $intVar = ($hours * 60) + $minutes;
> return($intVar);
> // echo "alert('$intVar')"; // <-- this will fail because it won't echo
> after a return statement
> }
>
>
> "PSI_Orion" <orion@psiss.com> wrote in message
> news:34tvg.29416$IU2.17330@newsfe2-win.ntli.net...
>> Further to my last post, I was slightly incorrect with what I was
>> stating.
>> If the sscanf line is uncommented only then the function still works
>> (returns the echo). However, if I don anything AFTER the sscanf, the
>> function fails.
>>
>> so...
>>
>> function timeToInt($timeVar)
>> {
>> echo "alert('$timeVar')";
>> sscanf($timeVar,"%d:%d",$hours,$minutes);
>> // echo "alert('$timeVar')";
>> // echo "alert('$minutes')";
>> // $intVar = ($hours * 60) + $minutes;
>> // return($intVar);
>> // echo "alert('$intVar')";
>> }
>>
>> works and return an echo but...
>>
>> function timeToInt($timeVar)
>> {
>> echo "alert('$timeVar')";
>> sscanf($timeVar,"%d:%d",$hours,$minutes);
>> echo "alert('$timeVar')";
>> // echo "alert('$minutes')";
>> // $intVar = ($hours * 60) + $minutes;
>> // return($intVar);
>> // echo "alert('$intVar')";
>> }
>>
>> fails and doesn't so something is wrong with the sscanf call. Could it
>> be
>> the variable naming?
>>
>> "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

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