Re: Determine the difference between two dates
| From: | Pedro Garre | Date: | Fri, 19 Apr 2002 20:36:09 +0000 |
| Subject: | Re: Determine the difference between two dates | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93692@lists.php.net to get a copy of this message | ||
*This message was transferred with a trial version of CommuniGate(tm) Pro*
Yes, but note that strtotime has a second parameter, which is "now" if
not indicated.
What strtotime returns is relative to this second parameter.
I would use:
$ahora = time();
$firstTime=strtotime($firstTime, $ahora);
$lastTime=strtotime($lastTime, $ahora);
Pedro.
Danny Shepherd escribió:
>
> *This message was transferred with a trial version of CommuniGate(tm) Pro*
> Firstly, I assume you mean "Y-m-j H:i:s" for the date format.
>
> To get the difference between 2 time strings :
>
> <?php
>
> // orginal time strings
> $firstTime="2002-04-19 13:49:00";
> $lastTime="2002-04-19 14:00:00";
>
> // convert to unix timestamps
> $firstTime=strtotime($firstTime);
> $lastTime=strtotime($lastTime);
>
> // perform subtraction to get the difference (in seconds) between times
> $timeDiff=$lastTime-$firstTime;
>
> //echo out the difference
> printf ("Difference is %d seconds",$timeDiff);
>
> ?>
>
> HTH
>
> Danny.
>
> ----- Original Message -----
> From: "Ron Allen" <allenr@fwd.areur.army.mil>
> To: <php-general@lists.php.net>
> Sent: Friday, April 19, 2002 1:08 PM
> Subject: [PHP] Determine the difference between two dates
>
> > If I have two variables of time both in the format of "Y-m-j J:i:s"
> > How would I go about and get the difference?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php