Forum Moderators: coopster

Message Too Old, No Replies

Calculate number of days between 2 dates

         

turbohost

11:02 am on Jan 27, 2005 (gmt 0)

10+ Year Member



Hi Guys,

How can I calculate the number of days between 2 dates in PHP?

Thx,
Turbo

dreamcatcher

11:55 am on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First Date: 1 January 2005
Second Date: 27 January 2005


$first_date = mktime(12,0,0,1,1,2005);
$second_date = mktime(12,0,0,1,27,2005);

$offset = $second_date-$first_date;

echo floor($offset/60/60/24) . " Days";

This will display:

26 Days.

dc

Romeo

12:30 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Hi Turbohost,

as you didn't tell more about those dates you have, you should be aware that Dreamcatcher's script will handle short term dates within the unix epoch only, that is 1970-01-01 ... 2038-01-19.
If you would like to count the days since your grandmother's birthday, it will get more complicated.

Regards,
R.

coopster

3:16 am on Jan 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another trick is to use your database to do the work for you.