Jump to content

HOW TO SUBTRACT YYYY-MM-DD FROM YYYY-MM-DD


dlebowski

Recommended Posts

assuming the dates are always valid, clever use of the strtotime function would work

$date1 = "2010-01-01";
$date2 = "2010-01-25";
$time1 = strtotime($date1);
$time2 = strtotime($date2);
$diff = abs($time2-$time1);
//convert seconds to days
$diff /= 60 * 60 * 24;//60 secs a min / 60 mins an hour / 24 hours a day
echo ceil($diff);

 

output:

24

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.