I have a datetime
field in my database that contains the following information:
2015-08-04 18:59:01
I want to check the difference between that datetime
field and now using Cakephp framework
?
I have a datetime
field in my database that contains the following information:
2015-08-04 18:59:01
I want to check the difference between that datetime
field and now using Cakephp framework
?
See DateTime::diff
$date = '2015-08-04 18:59:01';
$dateTime = new DateTime($date);
$now = new DateTime();
$interval = $now->diff($dateTime);
echo $interval->format('%R%a days');
See DateInterval::format for other formatting options.
You can also get diff in seconds:
$date = '2015-08-04 18:59:01';
$dateTime = new DateTime($date);
$diff = time() - $dateTime->getTimestamp();
Calculate the difference between two dates:
Output: +272 days
The date_diff() function returns the difference between two DateTime objects.