|
Posted by Hans 'pritaeas' Pollaerts on 07/19/06 17:04
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
> >> >
> >> >
> >>
> >>
> >
> >
>
>
[Back to original message]
|