Year 2038 Problem

Feb 28, 2022

On January 19th 2038 at 03:14:08 UTC many computer programs will inadvertently stop working. Some will crash, others will report the time as December 13th 1901 at 20:45:52 UTC. A flashback to Y2K, we'll have Y2k38.

Why? Many programs measure time in Unix time, which is the number of seconds elapsed since the Unix epoch (January 1st 1970 00:00:00 UTC). The current epoch time of this post is 1,646,058,600. On January 19th 2038, Unix time will reach an important number to computer scientists, 2,147,483,647.

2,147,483,647 can also be written as 231 − 1. Unix timestamps usually are stored in 32-bit signed integers. A 32-bit signed integer uses the first bit to determine the sign, and the next 31 to encode the number, so it can represent integers from −(231) to 231 − 1.

When a 32-bit signed integer overflows, or goes beyond its maximum value, it flips the signed bit, or −(231). Unix timestamps stored in 32-bit integers that overflow will read −(231), or 231 seconds before epoch – December 13th 1901.

Many programs have already safeguarded against this by storing Unix timestamps in a 64-bit integer (that kicks the problem 292 billion years into the future), but some legacy programs will inevitably fail in unexpected ways. We'll have a lot more legacy software in 2038 than we did in 2000 (Y2K).

Subscribe for daily posts on startups & engineering.