Accessing Dates in PHP Beyond 2038

Accessing dates in PHP beyond 2038

You can alternatively use the DateTime class, which internally represents the time components independently. Thus it is not susceptible to the 2038 limitation (unless you use ::getTimestamp).

touch function in PHP 7 64-bit does not handle dates beyond 2038

I reported it as a bug in PHP and it was fixed the next day!

Bug #78241 is fixed starting with PHP 7.3.8 & 7.2.21.

Why can't I add more than 7400 days to date in php?

Likely it is due to the Year 2038 problem combined with a 32bit version of PHP.

You can check your php version by checking the value of the PHP_INT_SIZE constant (which will be 4 for x32 and 8 for x64).

Any dates after january 19'th 2038 overflows the 32-bit signed integer used for the Unix timestamp.

5000 days from today is March 27, 2032

7500 days from today is January 30, 2039

Using a 64bit version of PHP you should be good until year 292277026596.

Why do timestamps have a limit to 2038?

The limit is imposed by the 4 byte signed integers that most C libraries use for representing that count. Quick math (assumes 365 day years, not exactly correct):

2147483648 seconds ~ 68.1 years

This also implies a lower limit of ~1900. Some libraries have started to introduce 64 bit epoch counts, but they are few and far between for the moment.



Related Topics



Leave a reply



Submit