Convert Date time into Seconds
| From: | kvigor | Date: | Sun, 24 Jun 2007 02:29:37 +0000 |
| Subject: | Convert Date time into Seconds | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-257715@lists.php.net to get a copy of this message | ||
Good Day,
I'm chech if 24hrs has passed between these 2 datetimes:
$dTime1 = 2007-06-21 11:08:09;
$dTime2 = 2007-06-22 07:08:09;
I'd really like to convert the datetimes above into a format I can do
regular math them.
Browsing around I've found the following code. But both weren't clear on
what to pass to them. Because when I pass a datetime var to them and echo
the value I get no output please help.
======================================================================
function datetime_to_epoch($date)
{
$break = explode(" ", $date);
$datebreak = explode("-", $break[0]);
$time = explode(":", $break[1]);
$epoch = date("U",
mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0]));
$datetime = date("Y-m-d H:i:s",
mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0]));
}
?>
=======================================================================
function convert_datetime($varStamp) {
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}
//If anyone could elaborate, would be appreciated.
================================================================================