查找两个日期之间的天数差异,其范围为数千年


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

我们如何在PHP中找到日期差异,日期可能在1/1/1到1/1/100000之间。

strtotime()、mktime()、date->diff()所有这些函数都没有帮助,因为它超过了Unix时间戳的限制。

据我所知,DateTime允许任何时间段的日期。甚至在unix之前。

它很可能会在10000000年1月1日失效,但这需要测试。

要获得差异,请使用Diff

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

如果Diff在您的范围内不起作用,请尝试https://stackoverflow.com/a/676828/486780。

DateTime可能能够存储日期,但如果您使用其他辅助函数,它们将不起作用,因为它们使用基本类型而不是更结构化的表示。您可能需要创建自己的实用程序。