2

Well, this may be a stone age question, but I got confused after reading so many questions here.

  1. A simple solution using strtotime() has been pointed out here, but the last comment about time change for the accepted answer leads me to diff function.

  2. Many of the links suggest me to diff function , something like Calculate number of hours between 2 dates in PHP.

    • But then I saw a PHP bug that diff shows wrong values when first date of the days are involved (link).

    • Also days part on diff function always return 6015 on Windows platform (link).

I read many more links and all of them ends with diff() function. Is there a reliable solution for this problem?

Note: I am using PHP version 5.3.5

Community
  • 1
  • 1
Abel
  • 2,371
  • 3
  • 15
  • 29

1 Answers1

-1

If you don't want to use datediff neither strtotime, one more solution is to use getTimestamp and calc the difference

$datetime1 = new DateTime('13-03-01');
$datetime2 = new DateTime('13-04-01');

$datetime1TS = datetime1->getTimestamp;
$datetime2TS = datetime2->getTimestamp;

$interval = ($datetime2TS - $datetime1TS)/(60*60*24);

But i think that datediff is better.

fasenderos
  • 388
  • 3
  • 18
  • 1
    But it will be same as strtotime, compare it with the link I provide in the first both will be same. – Abel May 01 '14 at 13:30