4

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.2

Community
  • 1
  • 1
hbt
  • 1,011
  • 3
  • 16
  • 28

2 Answers2

3

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.

Ibrahim AshShohail
  • 2,072
  • 14
  • 19
  • `runkit` is an option, but its last update dates back to 2006, so it probably won't work will recent versions of PHP (`apd` is even worse). – netcoder Aug 26 '11 at 13:48
  • 1
    Update to 64-bit will indeed solve this problem. Although, I would consider switching to the DateTime extension. – Narf Aug 27 '11 at 00:28
0

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.

Brent Baisley
  • 12,641
  • 2
  • 26
  • 39
  • Thanks. However, that means I will have to refactor every call made using strtotime to gregoriantojd -- which is pretty much similar to solution 2 except gregoriantojd only works with dates and not necessarily timestamps. – hbt Aug 26 '11 at 13:34
  • Whine, whine, whine :) Until fairly recently, most standard time/date functions on most OS's couldn't express a date earlier than Jan 1, 1970. And reverted back to "0" on Jan 19, 2038. http://en.wikipedia.org/wiki/Year_2038_problem. The workaround, of course, was to not use standard date/time functions - to store the date in some other format (for example, the string "1/1/1 a.d.". – paulsm4 Aug 27 '11 at 04:26