PHP strtotime returns false for dates less than 1900

I know this question is very popular.

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

Could you confirm my choices:

  • Upgrade to 64-bit architecture

  • Replace strtotime calls with DateTime + DateInterval We cannot call DateTime-> getTimestamp, but we can use DateInterval to calculate diff

Do I have any other options? Unfortunately, I cannot choose option 2 because I rely on ORM (Propel) + a lot of legacy code using strtotime. Refactoring this material + tuning ORM generators can be more expensive than upgrading to 64 bits.

If anyone can confirm or suggest any other options, that would really be appreciated.

thanks

Date Format - Standard yyyy-mm-dd

PHP version 5.3.2

+4
source share
2 answers

AFAIK, you are limited to these two solutions.

You should upgrade to a 64-bit system, if you can afford it, and if it solves the problem, then this is better.

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

+3
source

You can use gregoriantojd, which has a date range of 4714 BC to 9999 AD. A much wider range than 1900 (1970) -2038. If you are trying to calculate the differences by date, they are pretty close. Well, with the exception of the β€œlost” 10 days, October 4-14, 1582. And because of the different calculation of a leap year, you will be disconnected for one day every 100 years.

0
source

Source: https://habr.com/ru/post/1369069/


All Articles