Access dates in PHP beyond 2038

I understand that because PHP represents dates using milliseconds, you cannot represent dates that have passed in 2038. I have a problem when I want to calculate dates in the future. Thousands years.

Obviously, I cannot use the php date function to represent this date due to a limitation, however, I have something on my side ... All I want to do is store the year, month and day. I am not interested in hour, minute, second and millisecond.

Do I correctly believe that without including this additional information, I would have to calculate a lot more in the future, because I am ready to refuse a lot of information. Is this some kind of library that is currently doing this? If there is no advice on how to approach this issue?

+12
date php timestamp time year2038
Mar 16 2018-11-11T00:
source share
5 answers

Alternatively, you can use the DateTime class, which independently represents the time components independently. Thus, it is not subject to the 2038 limit (unless you use :: getTimestamp).

+20
Mar 16 2018-11-11T00:
source share

You can use the 64-bit platform.

The size of the integer depends on the platform, although the maximum value of about two billion is the usual value (this is 32 bits). 64-bit platforms typically have a maximum value of about 9E18.

Source

Find out that your platform has 64 bits with var_dump(PHP_INT_SIZE === 8) . If TRUE , your system will be 64 bits.

+5
Mar 16 2018-11-11T00:
source share

You are correct that PHP does not allow processing dates> 2038, initially. However, there are libraries, such as this one , that use the fact that floating point is 64 bits, which allows you to work around this problem if necessary (All under the assumption that you are using a 32-bit system ... if you are using 64-bit , are you okay).

+1
Mar 16 2018-11-11T00:
source share

PHP introduced the Datetime () class in version 5.2 to solve this problem. But you should still be on a 64-bit OS.

+1
Mar 16 2018-11-11T00:
source share

Forget about Windows! Even if you are using the 64-bit version of Apache 64-bit for Windows!

 $timestamp = strtotime('22-09-2508'); var_dump ($timestamp); // returns bool false using WAMP 64-Bit over Windows 64 Bit 

If you need to calculate timestamps, use a 64-bit system (not Windows):

 $timestamp = strtotime('22-09-2508'); var_dump ($timestamp); // returns int 17000496000 using a LAMP Server 

You can start the LAMP server using VMWare through Windows, and most likely your final host server will also use this 64-bit service.

In other words:

 if (intval("9223372036854775807")==9223372036854775807) { // 64-bit } else { // 32-bit } 

Got?

Note: time () and getTimestamp () work fine in a 64-bit (linux) environment after 2038.

0
Jun 30 '14 at 6:24
source share



All Articles