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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -