You might need to calculate the date difference in days using PHP. You can easily calculate the days difference by using something like the code below.
The code shown above takes the UNIX timestamp of two dates and subtracts the older date from the newer date to get the number of seconds. Then we simply divide the seconds by 60 (since there are 60 seconds in a minute) to get the minutes, again by 60 (since there are 60 minutes in an hour) to get the hours and lastly by 24 (since there are 24 hours in a day) to get the number of days.
You don’t have to subtract the newer date from the older date though since we’re making use of the php abs() function which will automatically return an absolute value and eliminate a minus sign to make a negative value positive.
I hope that helps!

















August 11th, 2008 at 5:03 am
Really helpful!!!!!!!!!
September 9th, 2008 at 5:46 am
Indeed.
I was working on an old site that only had version 4.0 of MySQL installed so no DATEDIFF command.
Your code above allowed me to do the calculation almost as easily in PHP.
November 22nd, 2008 at 10:31 am
ohh dear..itz so easy…just tell me how to get end date from starting date and number of days + time , and also eliminate the weekends..
January 16th, 2009 at 5:37 am
This technique is daylight saving proof, because the one hour is everytime rounded correctly.
March 2nd, 2009 at 5:06 am
how can i create a form that store data that is fed on it to the database and can calculate the date from which a customer logs in for booking in a hotel and on the day when he/she checks out it automatically calculates the days spent and amount to be paid and declares the room vacant
March 13th, 2009 at 12:56 pm
Can you show the code for the calculation of the date difference? Thank you.
May 26th, 2009 at 9:06 am
where is the code?
May 29th, 2009 at 3:04 am
where the hell is the coooode ?
July 8th, 2009 at 1:17 am
where is the code plssssssssssss
July 25th, 2009 at 5:53 pm
uhm, I don’t see any code…?!
August 2nd, 2009 at 12:22 am
Good thinking, this is way easier then the calculation in PHP itself…
August 19th, 2009 at 4:59 am
reeeeeeeeeee there no code
August 19th, 2009 at 5:00 am
conde is not there