Re: Date Subtraction
| From: | Marco Tabini | Date: | Mon, 23 Dec 2002 22:01:05 +0000 |
| Subject: | Re: Date Subtraction | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-129231@lists.php.net to get a copy of this message | ||
I don't think you can use strtotime in that case. However, assuming that
your data is properly formatted every time, you can use a simple
function like this (I'm doing it from memory, so it might not actually
work):
<?php
function conv_time ($s)
{
preg_match ("/^([0-9]*) days,
([0-9]*)\:([0-9]*)\:([0-9]*)(\.[0-9]*)$/", $s, $res);
return $res[1] * 86400 + $res[2] * 3600 + $res[3] * 60 + $res[4] +
$res[5];
}
echo number_format (conv_time ("181 days, 7:16:6.75") - conv_time ("181
days, 7:11:06.66"), 2);
?>
Hope this helps.
Cheers,
Marco
--
------------
php|architect - The Magazine for PHP Professionals
The monthly magazine dedicated to the world of PHP programming
Check us out on the web at http://www.phparch.com!