In my last post about Converting Your Date from date/time into timestamp using PHP I have make a explanation how to convert from date/time into timestamp format in PHP. Now I will make a post about how to make a datetimediff in PHP. I will use TimeStamp format for this example. Let’s see if we can do it. Why to use timestamp format? I think this is the standard format for time formatting.
CMIIW
In my time zone, I will set it to Asia/Jakarta because my I live in Jakarta so I will match with it.
<?php
class DateUtil {
public static function dateDiff($_date) {
date_default_timezone_set('Asia/Jakarta');
$today = time();
$date = strtotime($_date);
return $today - $date;
}
}
$myDate = '2010-06-28 12:46:36';
echo DateUtil::dateDiff($myDate) .' seconds';
?>
It will return the difference time (now) and your input time.