Bug #38457 NOW() loses time information when writing to TIMESTAMP field
| Submitted: | 30 Jul 2008 12:38 | ||
|---|---|---|---|
| Reporter: | Domas Mituzas | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
| Version: | 4.1, 5.0, 5.1, etc | OS: | Any |
| Assigned to: | Assigned Account | CPU Architecture: | Any |
| Tags: | daylight, timestamp, timezone | ||
[30 Jul 2008 12:38]
Domas Mituzas
[3 Aug 2009 14:38]
Martin Stjernholm
This problem also affects FROM_UNIXTIME(). One would expect that having a TIMESTAMP column which is always set through FROM_UNIXTIME() and always read through UNIX_TIMESTAMP() would be safe from calendaric discontinuities etc, but that is not so. An example, assuming that the active time zone on the connection is Europe/Stockholm (aka CET): mysql> CREATE TABLE test (ts TIMESTAMP DEFAULT 0); mysql> INSERT INTO test SET ts = FROM_UNIXTIME(1130630400); mysql> SELECT UNIX_TIMESTAMP(ts) FROM test; +--------------------+ | UNIX_TIMESTAMP(ts) | +--------------------+ | 1130634000 | +--------------------+ Note the 1 hour difference between the set value and the retrieved one. A workaround is to change the timezone on the connection to one that doesn't use DST: mysql> SET time_zone = '+00:00'; mysql> CREATE TABLE test (ts TIMESTAMP DEFAULT 0); mysql> INSERT INTO test SET ts = FROM_UNIXTIME(1130630400); mysql> SELECT UNIX_TIMESTAMP(ts) FROM test; +--------------------+ | UNIX_TIMESTAMP(ts) | +--------------------+ | 1130630400 | +--------------------+
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.049 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.