简体   繁体   中英

Find days difference between two dates with range of thousands of year

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM