Re: Time to Calculate Time
| From: | Richard Lynch | Date: | Tue, 09 Jul 2002 09:22:58 +0000 |
| Subject: | Re: Time to Calculate Time | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-106318@lists.php.net to get a copy of this message | ||
>i have variables $Start, $End each with a timestamp 2 hours apart
>(20020707140000, 20020707160000) respectively....
01234567890123
>
>How do i calculate those to timestamps to get the answer 2?????
>
>I've tried working them into unix timestamps and then calculating but no
>luck...
>
>any one got any ideas ??
I'm guessing these are coming from MySQL... If so, you can subtract the two
in MySQL much easier/faster than PHP...
http://mysql.com/
If not:
$s = mktime(substr($Start, 8, 2), substr($Start, 10, 2), substr($Start, 12,
2), substr($Start, 4, 2), substr($Start, 6, 2), substr($Start, 0, 4));
$e = mktime(substr($End, 8, 2), substr($End, 10, 2), substr($End, 12, 2),
substr($End, 4, 2), substr($End, 6, 2), substr($End, 0, 4));
$delta = $e - $s;
At this point, it boils down to the question -- Will it ever be, like,
*DAYS* instead of hours, or, more importantly, *MONTHS*?
Because as soon as you get into "months" or larger time units, it gets
complicated...
Until then, you can divide by 60, or 60*60, or 60*60*24 to get the number of
minutes, hours, days respectively...
--
Like Music? http://l-i-e.com/artists.htm