Why will some computers run out of time on 19th January 2038?

Akash Poudel
5 min readDec 11, 2022

Have you ever wondered, How computers store time?
But if ‘t be true thee didst not knoweth, thou art in safe hands because the present day I shall bid thee how :P
Also, we will discuss how some systems may crash on 19th January 2038 and see how chaotic this is.

How do computers store time?

Computers have a weird way of storing information about the current date and the time.
A hardware perspective:
Before the internet days, there was a Real Time Clock(RTC), a circuit designed to keep track of the system baked into the motherboard.
A small CMOS battery is packed inside the motherboard, which keeps the computer system’s clock ticking, even when the system is powered off. These days we have NTP servers to communicate for Time if connected to the internet so the hardware clock can be synced easily. Please let me know if you want a tutorial on how to do that!

A Real Time Clock(RTC) hardware
A Battery is Embedded inside the RTC hardware to keep the clock ticking.

A Digital Perspective:
It stores the date in the form of digits. There is an Epoch Time based on the Operating System used.
What is Epoch time?
Epoch time is the time measured in seconds elapsed from a particular time.
For instance;
If the Epoch System is set to January 2000 00h:00m:00s UTC for a particular Operating System, it maintains a counter called the Epoch time.
For every second that passes, it increases the Epoch Time by 1.
This Epoch time is finally stored as signed 32-bit integers inside some register, which can be decoded later to find the date.
The epoch time was introduced because it fixed the tedious problem of storing date and time in the form of years, months, days and time in the form of hours, minutes and seconds. Also, there are time zones, so it might get messy.
Hence, this solution was adapted to make things simpler.

UNIX Epoch time:
UNIX-based systems have their own Epoch time, i.e. UNIX Epoch Time. Its Epoch time is set to be 1st January 1970, 00h:00m:00s. It counts the number of seconds it has passed since the Epoch time. It is a numeric value stored as a 32-bit signed integer.

Do you see the problem yet?

We have 32 bits. The range of a 32-bit signed integer is
[-2³¹,(2³¹)-1].

This means these Unix-based systems have their clock ticking.
So when do we run out of time?
It is 2038, January 19th January 03h:14m:07s on UTC +00:00 time.

The end of the world? Kidding :P

But why does this problem occur?
As we know, 32-bit signed digits range to (2³¹)-1, which is precisely 2147483647.
After we increase one more to it, it will overflow.
This is clearer if we see the binary representation of the epoch time.
This is a classic integer overflow problem.
And the overflow can be seen below.

We can see the overflow live in action.

Some Implications of this:
In most UNIX-based systems, you cannot set a time before January 1st 1970. This includes your Linux, your iPhone, and your Android too. Fun Fact: In 2016, iPhones crashed if the date was set as 1st January and was part of an integer underflow bug which got fixed later.

The Solution:

Well, I told you about the problem; we will run out of digits by 2038 to store the Epoch time. So does this mean every computer will go on crashing on 19th January 2038? The answer to this question may be complex.

The problem was that we were storing the date in 32 bits; if we stored it in something like a 64-bit integer, the situation would not even persist.
Most operating systems have already updated this and implemented the Epoch date storage in 64 bits. By using 64 bits to store the Epoch time, we would have 2⁶⁴-1 digits to represent, which is reasonably enough for now.
Windows, macOS, Android, and iOS have already rolled out the 64-bit version of their operating systems.
Even for 32-bit processors, some operating systems have released updates fixing the bug.
Talking about Linux, starting with the Kernel 5.6 patch, the problem has been fixed temporarily, even for 32-bit processors.

So, who is really affected?

Every system worldwide is not affected by this bug. As we discussed earlier, only a few systems remain affected by this bug. You shouldn't panic immediately; your computers aren't probably affected by this anymore.
Well, suppose you’re running a system with a kernel version lesser than 5.6 on a 32-bit processor. In that case, you will be hit by the 2038 bug. This is one example of the systems affected by this; there might be many of these systems apart from those mentioned earlier. Some reports suggest that a fraction of embedded systems might be affected by the 2038 bug. But we still have plenty of time to update and fix them.
It may not be as chaotic as we imagine, but there is still a distinct possibility that some systems will be affected, which will affect people in some way. :)

Writing these articles take a lot of effort and time. If you liked my article, give me a follow on medium or give a like to this if you find my articles useful. Do consider following me!
Adios!
Follow me on My Socials!
Twitter: https://twitter.com/akashp011
LinkedIn: https://linkedin.com/in/akashp011
Medium: https://b33pl0g1c.medium.com

--

--