RE: [PHP] date conversion and calculation problem...
| From: | Jason Murray | Date: | Tue, 13 Nov 2001 03:44:31 +0000 |
| Subject: | RE: [PHP] date conversion and calculation problem... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-74354@lists.php.net to get a copy of this message | ||
> I have 2 date string like this
>
> $t1 = "2001-11-12 17:30:10";
> $t2 = "2001-11-12 17:15:32";
>
> I need to substracts the number of seconds from $t2 from $t1
First, convert them to unix time format:
<?
Function dateTextToUnix($string)
{
$year = substr($string, 0, 4);
$month = substr($string, 5, 2);
$day = substr($string, 8, 2);
$hours = substr($string, 12, 2);
$mins = substr($string, 14, 2);
$secs = substr($string, 16, 2);
return mktime($hours, $mins, $secs, $month, $day, $year);
}
?>
So:
<?
$t1 = "2001-11-12 17:30:10";
$t2 = "2001-11-12 17:15:32";
$t1unix = dateTextToUnix($t1);
$t2unix = dateTextToUnix($t2);
$secondsdifference = $t2unix - $t1unix;
?>
(apologies for stuff that doesn't work, I've coded this in
the email and not tested it :))
Jason