Faqts : Computers : Programming : Languages : PHP : Function Libraries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

44 of 51 people (86%) answered Yes
Recently 9 of 10 people (90%) answered Yes


How do I calculate the difference between two dates to return the number of days?

Jun 16th, 2000 07:08
Marco Steinacher, Robert Brown, http://www.php.net/manual/html/function.mktime.html

You can do this with the following statement:
mktime() returns seconds since 1.1.1970 for the specified date.
Thus the difference mktime([date1])-mktime([date2]) tells us the 
seconds between [date1] and [date2].
If we divide the absolute value of this difference by the number of 
seconds per day (24*60*60=86400) we get the number of days between 
[date1] and [date2].
We want to know the difference between 31.12.1999 and 01.03.2000.
The following code tells us the answer:
   echo $diff;
The script-output is: 61
That is correct then:
  1 day  (31.12.99)
+31 days (in Jan.00)
+29 days (in Feb.00)
=61 days