year 2038 bug in MySQL

March 4, 2011

today I hit the “year 2038” bug.

while working on MySQL, I did something like:

mysql> create table y2038 (x timestamp);

mysql> insert into y2038 values ('1900-01-01');
Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> insert into y2038 values ('2050-01-01');
Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> select * from y2038;
+---------------------+
| x                   |
+---------------------+
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
+---------------------+
2 row in set (0.00 sec)

mysql> drop table y2038; -- damn

it turned out that MySQL’s TIMESTAMP only accepts dates between 1970-01-01 00:00:01 and 2038-01-19 03:14:07: everything outside this range will be truncated.

at least, it will not be called “Friday the 13th” bug!

use DATETIME instead! and RTFM before doing anything!

Advertisements

One Response to “year 2038 bug in MySQL”

  1. Mark Says:

    Or a better database.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: