Bug #19124 TIMESTAMP values not interpreted correctly

Submitted: 16 Apr 2006 3:01 Modified: 16 Apr 2006 16:52
Reporter: Baron Schwartz (Basic Quality Contributor) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.19-log OS:Linux (Gentoo GNU/Linux AMD64)
Assigned to: CPU Architecture:Any

[16 Apr 2006 3:01] Baron Schwartz
Description:
TIMESTAMP values seem to be interpreted incorrectly when they are to before 1970.  (My computer's clock is set to EDT, so a timestamp of 1 is evaluated as '1969-12-31 19:00:01' on my system).

The issue isn't when storing or calling functions, but only when retrieving values from a TIMESTAMP column.  Times before 1970 are interpreted as being in the range 2000-2069, as explained in http://dev.mysql.com/doc/refman/5.0/en/y2k-issues.html, but shouldn't be because they are not 2-digit years, they are 4-digit years.

I can also reproduce this on the 4.x series on 32-bit hardware.

How to repeat:
Here is a session that demonstrates the problem.  Notice how the value '1969-12-31 19:00:01' is retrieved as '2069-12-31 19:00:01' after it is stored in a TIMESTAMP column.

mysql> select from_unixtime(1), from_unixtime(2000000);
+---------------------+------------------------+
| from_unixtime(1)    | from_unixtime(2000000) |
+---------------------+------------------------+
| 1969-12-31 19:00:01 | 1970-01-23 22:33:20    |
+---------------------+------------------------+
1 row in set (0.00 sec)

mysql> create table test(i int primary key, t timestamp);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test(i) values(1),(2000000);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> update test set t = from_unixtime(i);
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> select * from test;
+---------+---------------------+
| i       | t                   |
+---------+---------------------+
| 1       | 2069-12-31 19:00:01 |
| 2000000 | 1970-01-23 22:33:20 |
+---------+---------------------+
2 rows in set (0.00 sec)

mysql> select i, cast(t as datetime) from test;
+---------+---------------------+
| i       | cast(t as datetime) |
+---------+---------------------+
| 1       | 1969-12-31 19:00:01 |
| 2000000 | 1970-01-23 22:33:20 |
+---------+---------------------+
2 rows in set (0.00 sec)

mysql> select i, t, from_unixtime(i) from test;
+---------+---------------------+---------------------+
| i       | t                   | from_unixtime(i)    |
+---------+---------------------+---------------------+
| 1       | 2069-12-31 19:00:01 | 1969-12-31 19:00:01 |
| 2000000 | 1970-01-23 22:33:20 | 1970-01-23 22:33:20 |
+---------+---------------------+---------------------+
2 rows in set (0.00 sec)
[16 Apr 2006 16:52] Shane Bester
Looks like a duplicate of http://bugs.mysql.com/bug.php?id=16327 (invalid TIMESTAMP values retrieved).  Please check that.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.