0

How can we find days difference in PHP where dates may very from 1/1/1 to 1/1/1000000.

strtotime(), mktime(), date->diff() all these function are not be helpful as it is more then limit of Unix timestamp.

Ritesh Chandora
  • 7,812
  • 5
  • 20
  • 37

2 Answers2

2

As far as I know, DateTime allows for dates in any periods of time. Even before unix.

Quite possibly it will fial on 1/1/10000000 but that needs testing.

To get the difference, use Diff

$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');

If Diff doesn't work on your ranges, try this https://stackoverflow.com/a/676828/486780 .

Community
  • 1
  • 1
ZorleQ
  • 1,386
  • 12
  • 23
0

DateTime may be able to store the date, but if you're using other helper functions they won't work, as they operate using basic types and not a more structured representation. You're likely going to need to create your own utilities.

css
  • 950
  • 1
  • 7
  • 26