Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do timestamps have a limit to 2038?

I just found out, running a calendar script, that timestamps in PHP has a limit to 2038. What does it really mean? Why is it 2038 instead of 2050 or 2039? Why a limit if timestamps just count seconds from a given date (1970)?

like image 428
Shoe Avatar asked May 04 '11 05:05

Shoe


People also ask

Why 2038 is the end of the world for computers?

Players of games or apps which are programmed to impose waiting periods are running into this problem when the players try to bypass the waiting period by setting the date on their devices to a date past 19 January 2038, but are unable to do so, since a 32-bit Unix time format is being used.

What caused Year 2038 problem?

The Year 2038 problem is caused by an insufficient number of bits (digits) chosen to represent time. This has been known as early as 2006, when companies started to implement software with code embedded to handle a database request that should “never” time out.

Will 32-bit computers stop working in 2038?

Any 32-bit development that has not been updated on January 19, 2038, one of three things will happen: It will start to give errors that will generate chain failures in the system. It will shut down and stop working forever. You will reset your time count and believe you are back to 1901.

What will happen to Unix time in 2038?

The end of time The most imminent overflow date is the 32-bit signed integer-based systems', scheduled for 19 January 2038, at 03:14:07 UTC. One second later, computers will fall back to 13 December 1901, at 20:45:52 UTC. This behavior is due to an integer overflow occurring at the time of adding the next second.


2 Answers

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.

like image 80
Matthew Scharley Avatar answered Sep 28 '22 03:09

Matthew Scharley


The maximum value of a 32-bit integer is 2,147,483,647. If you add +1 to that, you get -2,147,483,647. 2,147,483,647 seconds from 01-01-1970 00:00:00 is January 19, 2038. If you add one more second, you get a date somewhere in 1902.

like image 25
Sander Marechal Avatar answered Sep 28 '22 02:09

Sander Marechal