date - Get a PHP DateTime difference in days, considering midnight as a day change -
what simplest way difference in days between 2 php datetimes
, considering midnight day change (just datediff(day)
sql function does)?
for example, between today @ 13:00 , tomorrow @ 12:00, should 1 (day), though interval less 24 hours.
$date1 = new datetime("2013-08-07 13:00:00"); $date2 = new datetime("2013-08-08 12:00:00"); echo $date1->diff($date2)->days; // 0
you ignore time portion of date string
$date1 = new datetime(date('y-m-d', strtotime("2013-08-07 13:00:00"))); $date2 = new datetime(date('y-m-d', strtotime("2013-08-08 12:00:00"))); echo $date1->diff($date2)->days; // 0
Comments
Post a Comment