Posts Tagged ‘y2038’

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!