0

Possible Duplicate:
How to calculate the difference between two dates using PHP?

Hello everyone I need calculate the exact total number of days between two dates. It is easy to date using PHP DateTime object's diff() method. However I don't have access to PHP 5.3

So what is the best way to calculate total number of days beetwen two dates?

$date1 = new DateTime('2011-01-01');
$date2 = new DateTime('2011-04-23');
$totalDaysBetween = ???

It should also be able to handle leap years.

Any ideas?

Community
  • 1
  • 1
Sinan
  • 5,639
  • 10
  • 36
  • 65
  • PHP comments are your friend. http://php.net/manual/en/ref.datetime.php , scroll down to the comments for examples of using `strtotime` to compute the difference between dates while taking into account DST and leap years. – Dan Grossman Jul 16 '11 at 00:55
  • 4
    **This should not be closed as a duplicate**; the other question does not require PHP <5.3 solutions and its top answers do not even attempt to handle daylight savings and such. – Dan Grossman Jul 16 '11 at 00:59
  • 2
    @Dan: But the accepted answer linked to by Mitch specifically has a solution for pre-5.3 - it even accounts for leap years. The OP seems to only care about days judging by the code snippet - DST wouldn't apply here. – EboMike Jul 16 '11 at 01:03

0 Answers0