Year 2038 problem

The year 2038 problem (also known as Y2038, Y2K38, Y2K38 superbug or the Epochalypse ) is a time computing problem that leaves some computer systems unable to represent times after 03:14:07 UTC on 19 January 2038.

The problem exists in systems which measure Unix time&mdash;the number of seconds elapsed since the Unix epoch (00:00:00 UTC on 1 January 1970)&mdash;and store it in a signed 32-bit integer. The data type is only capable of representing integers between &minus;(2$31$) and 231 &minus; 1, meaning the latest time that can be properly encoded is 2$31$ &minus; 1 seconds after epoch (03:14:07 UTC on 19 January 2038). Attempting to increment to the following second (03:14:08) will cause the integer to overflow, setting its value to &minus;(2$31$) which systems will interpret as 2$31$ seconds before epoch (20:45:52 UTC on 13 December 1901). The problem is similar in nature to the year 2000 problem, the difference being the Year 2000 problem had to do with base 10 numbers, while the Year 2038 problem has to do with base 2 numbers.

Analogous storage constraints will be reached in 2106, where systems storing Unix time as an unsigned (rather than signed) 32-bit integer will overflow on 7 February 2106 at 06:28:15 UTC.

Computer systems that use time for critical computations may encounter fatal errors if the year 2038 problem is not addressed. Some applications that use future dates have already encountered the bug. The most vulnerable systems are those which are infrequently or never updated, such as legacy and embedded systems. Modern systems and software updates to legacy systems address this problem by using signed 64-bit integers instead of 32-bit integers, which will take 292 billion years to overflow—approximately 21 times the estimated age of the universe.

Cause
Many computer systems measure time and date using Unix time, an international standard for digital timekeeping. Unix time is defined as the number of seconds elapsed since 00:00:00 UTC on 1 January 1970 (an arbitrarily chosen time based on the creation of the first Unix system), which has been dubbed the Unix epoch.

Unix time has historically been encoded as a signed 32-bit integer, a data type composed of 32 binary digits (bits) which represent an integer value, with 'signed' meaning that the number can represent both positive and negative numbers, as well as zero; and is usually stored in two's complement format. Thus, a signed 32-bit integer can only represent integer values from &minus;(2$31$) to 231 &minus; 1 inclusive. Consequently, if a signed 32-bit integer is used to store Unix time, the latest time that can be stored is 231 &minus; 1 (2,147,483,647) seconds after epoch, which is. Systems that attempt to increment this value by one more second to 2$31$ seconds after epoch (03:14:08) will suffer integer overflow, inadvertently flipping the sign bit to indicate a negative number. This changes the integer value to &minus;(2$31$), or 2$31$ seconds before epoch rather than after, which systems will interpret as 20:45:52 on Friday, 13 December 1901. From here, systems will continue to count up, toward zero, and then up through the positive integers again. As many computer systems use time computations to run critical functions, the bug may introduce serious problems.

Vulnerable systems
Any system using data structures with signed 32-bit time representations has an inherent risk of failing. A full list of these data structures is virtually impossible to derive, but there are well-known data structures that have the Unix time problem:
 * File systems that use 32 bits to represent times in inodes
 * Binary file formats with 32-bit time fields
 * Databases with 32-bit time fields
 * Database query languages (such as SQL) that have -like commands

Embedded systems
Embedded systems that use dates for either computation or diagnostic logging are most likely to be affected by the Y2038 problem. Despite the modern 18–24 month generational update in computer systems technology, embedded systems are designed to last the lifetime of the machine in which they are a component. It is conceivable that some of these systems may still be in use in 2038. It may be impractical or, in some cases, impossible to upgrade the software running these systems, ultimately requiring replacement if the 32-bit limitations are to be corrected.

Many transportation systems from flight to automobiles use embedded systems extensively. In automotive systems, this may include anti-lock braking system (ABS), electronic stability control (ESC/ESP), traction control (TCS) and automatic four-wheel drive; aircraft may use inertial guidance systems and GPS receivers. Another major use of embedded systems is in communications devices, including cell phones and Internet-enabled appliances (e.g. routers, wireless access points, IP cameras) which rely on storing an accurate time and date and are increasingly based on Unix-like operating systems. For example, the Y2038 problem makes some devices running 32-bit Android crash and not restart when the time is changed to that date.

However, this does not imply that all embedded systems will suffer from the Y2038 problem, since many such systems do not require access to dates. For those that do, those systems which only track the difference between times/dates and not absolute times/dates will, by the nature of the calculation, not experience a major problem. This is the case for automotive diagnostics based on legislated standards such as CARB (California Air Resources Board).

Early problems
In May 2006, reports surfaced of an early manifestation of the Y2038 problem in the AOLserver software. The software was designed with a kludge to handle a database request that should "never" time out. Rather than specifically handling this special case, the initial design simply specified an arbitrary time-out date in the future with a default configuration specifying that requests should time out after a maximum of one billion seconds. However, one billion seconds before the 2038 cutoff date is 01:27:28 UTC on 13 May 2006, so requests sent after this time would result in a time-out date which is beyond the cutoff. This made time-out calculations overflow and return dates that were actually in the past, causing software to crash. When the problem was discovered, AOLServer operators had to edit the configuration file and set the time-out to a lower value.

Solutions
There is no universal solution for the Year 2038 problem. For example, in the C language, any change to the definition of the  data type would result in code-compatibility problems in any application in which date and time representations are dependent on the nature of the signed 32-bit   integer. For example, changing  to an unsigned 32-bit integer, which would extend the range to 2106 (specifically, 06:28:15 UTC on Sunday, 7 February 2106), would adversely affect programs that store, retrieve, or manipulate dates prior to 1970, as such dates are represented by negative numbers. Increasing the size of the  type to 64 bits in an existing system would cause incompatible changes to the layout of structures and the binary interface of functions.

Most operating systems designed to run on 64-bit hardware already use signed 64-bit  integers. Using a signed 64-bit value introduces a new wraparound date that is over twenty times greater than the estimated age of the universe: approximately 292 billion years from now. The ability to make computations on dates is limited by the fact that  uses a signed 32-bit integer value starting at 1900 for the year. This limits the year to a maximum of 2,147,485,547 (2,147,483,647 + 1900).

Alternative proposals have been made (some of which are already in use), such as storing either milliseconds or microseconds since an epoch (typically either 1 January 1970 or 1 January 2000) in a signed 64-bit integer, providing a minimum range of 300,000 years at microsecond resolution. In particular, Java's use of 64-bit long integers everywhere to represent time as "milliseconds since 1 January 1970" will work correctly for the next 292 million years. Other proposals for new time representations provide different precisions, ranges, and sizes (almost always wider than 32 bits), as well as solving other related problems, such as the handling of leap seconds. In particular, TAI64 is an implementation of the International Atomic Time (TAI) standard, the current international real-time standard for defining a second and frame of reference.

Implemented solutions

 * Starting with Ruby version 1.9.2 (released on 18 August 2010), the bug with year 2038 is fixed, by storing time in a signed 64-bit integer on systems with 32-bit.
 * Starting with NetBSD version 6.0 (released in October 2012), the NetBSD operating system uses a 64-bit  for both 32-bit and 64-bit architectures. Applications that were compiled for an older NetBSD release with 32-bit   are supported via a binary compatibility layer, but such older applications will still suffer from the Y2038 problem.
 * OpenBSD since version 5.5, released in May 2014, also uses a 64-bit  for both 32-bit and 64-bit architectures. In contrast to NetBSD, there is no binary compatibility layer. Therefore, applications expecting a 32-bit   and applications using anything different from   to store time values may break.
 * Linux originally used a 64-bit  for 64-bit architectures only; the pure 32-bit ABI was not changed due to backward compatibility. Starting with version 5.6 of 2020, 64-bit   is supported on 32-bit architectures, too. This was done primarily for the sake of embedded Linux systems.
 * GNU C Library since version 2.34 (released August 2021), added support for using 64-bit  on 32-bit platforms with appropriate Linux versions. This support can be activated by defining preprocessor macro   to   when compiling source code.
 * FreeBSD uses 64-bit  for all 32-bit and 64-bit architectures except 32-bit i386, which uses signed 32-bit   instead.
 * The x32 ABI for Linux (which defines an environment for programs with 32-bit addresses but running the processor in 64-bit mode) uses a 64-bit . Since it was a new environment, there was no need for special compatibility precautions.
 * Network File System version 4 has defined its time fields as  since December 2000. Version 3 supports unsigned 32-bit values as  . Values greater than zero for the seconds field denote dates after the 0-hour, January 1, 1970. Values less than zero for the seconds field denote dates before the 0-hour, January 1, 1970. In both cases, the nseconds (nanoseconds) field is to be added to the seconds field for the final time representation.
 * The ext4 filesystem, when used with inode sizes larger than 128 bytes, has an extra 32-bit field per timestamp, of which 30 bits are used for the nanoseconds part of the timestamp, and the other 2 bits are used to extend the timestamp range to the year 2446.
 * The XFS filesystem, starting with Linux 5.10, has an optional "big timestamps" feature which extends the timestamp range to the year 2486.
 * While the native APIs of OpenVMS can support timestamps up to 31 July 31086, the C runtime library (CRTL) uses 32-bit integers for . As part of Y2K compliance work that was carried out in 1998, the CRTL was modified to use unsigned 32-bit integers to represent time; extending the range of   up to 7 February 2106.
 * PostgreSQL since version 7.2, released 2002-02-04, stores timestamp WITHOUT TIMEZONE as 64-bit. Prior versions already stored timestamp as 64-bit.
 * As of MySQL 8.0.28, released in January 2022, the functions,  , and   handle 64-bit values on platforms that support them. This includes 64-bit versions of Linux, MacOS, and Windows.  In older versions, built-in functions like   will return 0 after 03:14:07 UTC on 19 January 2038.