开发者

PHP strtotime returning false for dates less than 1900

开发者 https://www.devze.com 2023-03-31 09:19 出处:网络
I know this question is very popular Asked here PHP: strtotime is returning false for a future date? and here How can I work with dates before 1900 in PHP?

I know this question is very popular

Asked here PHP: strtotime is returning false for a future date? and here How can I work with dates before 1900 in PHP?

Could you please confirm my choices:

  1. Upgrade to a 64bit architecture

  2. Replace the strtotime calls by DateTime + DateInterval We can't call DateTime->getTimestamp but we can use DateInterval to calculate the diff

Do I have any other options? Unfortunately, I can't pick option 2 because I am relying on ORM (Propel) + a lot of legacy code using strtotime. Refactoring this stuff + customizing the ORM generators could be more expensive than upgrading to 64bits.

If anybody could confirm or offer any other options, that would be really appreciated.

Thanks

The date format is the standard yyyy-mm-dd

PHP Version 5.3.开发者_如何学Go2


AFAIK, you are limited to these two solutions.

You should update to 64-bit system if you can afford it, and if it solves a problem then that's better.

Edit: Just had to check: http://php.net/manual/en/function.runkit-function-redefine.php You could probably try and redefine strtotime() to work with dates prior to 1901.


You can use gregoriantojd, which has a date range of 4714 B.C. to 9999 A.D. A much wider range than 1900(1970)-2038. If you are trying to calculate date differences, they are close enough. Well, except for the "lost" 10 days October 4-14, 1582. And because of different leap year calculation, you will be off by a day every 100 years.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号