Calculate days between dates

Using php strtotime function difference between dates:

//number of seconds between two dates
$s = strtotime("2012-02-21 00:00:00") - strtotime("2011-02-21 00:00:00");
//how many days between two dates
echo $s/60/60/24;

Another way to set date with mktime function:

//number of seconds between two dates
$s = mktime(0, 0, 0, 21, 02, 2012) - mktime(0, 0, 0, 21, 02, 2011);
//how many days between two dates
echo $s/60/60/24;

Before PHP 5.1.0 negative timestamps were not supported. Under any known version of Windows date could be from 1970 to 2038 years.

And using MySQL difference between dates:

SELECT TO_DAYS('2012-02-21 00:00:00') - TO_DAYS('2011-02-21 00:00:00');
This entry was posted in Programming and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *