Computer Programming - The Year 2038 Problem

The common computer uses Binary (Base 2); each bit of information can be set to either "0" or "1". In order to represent more than two states we have to put multiple bits together to form a data type. Put eight togther to make a "byte". 00000000 to 11111111 gives 2^8 = 256 different values. There are many 8-bit computers around. As time went on 16-bit, 32-bit, 64-bit, 256-bit, 1024-bit computers were made. The typical home "PC" computer is 32-bit; the largest data type it natively supports is 32 binary digits long = 2^32 = 4,294,967,296. Considering that number lines are centred around 0, this gives a maximum positive number of 2,147,483,647. "Epoch Time" was defined as the number of seconds since 1970-01-01 00:00:00. Thus 32-bit computers, using epoch time can work normally up to Tuesday 2038-01-19 03:14:07.

Databases have a data type called "DateTime", this supports up to 9999-12-31 23:59:59. PHP 5.2 onwards has an Object called DateTime that is also safe to use.

PHP Code

There is a lot of PHP code that uses "time", "date", "gmdate" functions. "time" returns epoch time as an "int". "int" on 32-bit platform has the 2038 problem, but on a 64-bit platform "int" is 64-bit so does not have the problem. You can test your server with the code:

$d = new DateTime();
echo $d->format('Y-m-d H:i:s')." ~~~~ ".date('Y-m-d H:i:s', PHP_INT_MAX);

Stored Times

If you store time on a CD, USB stick, hard drive.... then it will be stored using a certain number of bytes on disk. If written using a 32-bit computer, it each date time is probably stored using a 32-bit integer. When reading 32-bit file types on a 64-bit platform, the simplest thing to do is to store them in a 64-bit data type, but you don't have that luxury if the hardware is 32-bit.

8-bit devices that store year, month, day, hour, minute, seconds, in different variables will continue to work.

Issues / Bugs / Fixes

8-bit, 16-bit and 64-bit systems will be fine, provided they were properly coded.

32-bit systems using basic epoch time stored as a signed integer will see the time jump back, and tick forwards from 1970-01-01 00:00:00

Computer code that simply does a "if(timeA < timeB)" will cease to work.

Most professionally written code since 1985 that has been written for applications designed to last 20+ years don't do this kind of simple logic, and first look to see if the earlist time is before 2004 (half way though the supported period).

Reading old binary based files will be one of the trickiest issues.

Conclusion

Tuesday 2038-01-19 03:14:08 is the magic time.

  1. Some devices will simply loop back and tick forward from 1970-01-01 00:00:00
  2. Some devices will loop back and tick forward from 1901-12-13 20:45:52
  3. Badly coded real-time systems might stop working. Crash or overheat (due to stuck in tight loop)
  4. Computers that communicate with each other using 32-bit binary time, might see corruption
  5. Badly coded databases might see corruption or mass record deletion.

If your systems use date time, you can test them well ahead of 2038. Some code written using older languages might take a while to have upgraded.


Decimal Time

With Decimal Time, each Day has 10 equal Hours. The first 5 hours we call "AM" (Ante Meridiem meaning before midday) or "Morning", the later 5 we call "PM" (Post Meridiem meaning after midday) or "Afternoon". Each Hour is divided into 100 equal Minutes. Each Minute is divided into 100 equal Seconds. There is therefore 100,000 seconds in a day.

It is very easy to add and subtract Decimal Times which is why it is commonly used in Accounting and Time Logging systems.

When using Decimal Time we write the Year number followed by a Decimal Day number since the start of the Year: 2020-36.75000
In this case we are 3/4 of the way through Day 36 of the Year 2020.

The current Decimal Time is: Tuesday 2020-62.09299
Format: <yyyy-d.hmmss>
Description: yyyy = Year, d = Day (0-365), h = Hour (0-9), mm = Minute (00-59), ss = Second (00-59)

Typically we don't write the second (just the hour and minute) so we write: Tuesday 2020-62.092



Decimal seconds simply introduces a sixth / seventh... digit.
The following shows the current decimal time accurate to a micro decimal second (μs).

Tuesday 2020-62.09299308430


 
computer programming 2038 time problem on Twitter computer programming 2038 time problem on Facebook computer programming 2038 time problem on LinkedIn computer programming 2038 time problem on NotePage Note this page enquiriesforbrains.co.uk
+44 7703 184 699
A ForBrains Ltd Optimised Website, Web Content Management System
Connected via IPv4 from 3.141.41.187
Saturday 2024-110.44446
Copyright © 2020 ForBrains Ltd. All Rights Reserved.
It is 20/04/24 10:40 and 10o few clouds; later Clouds, tomorrow . Wind Direction: NW 310o, 3 mph. Sunrise: 05:00. Sunset: 19:18
ForBrains Ltd RSS
computer programming 2038 time problem
 
live online chat
login ▼