Bug #75006 time_zone works different for DateTime and TimeStamp
Submitted: 26 Nov 2014 9:39 Modified: 10 Dec 2014 12:49
Reporter: Michael Prokopiv Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S2 (Serious)
Version:mysql-5.6.21 ndb-7.3.7 OS:Any
Assigned to: CPU Architecture:Any
Tags: time_zone DateTime TimeStamp

[26 Nov 2014 9:39] Michael Prokopiv
Description:
Changing time_zone setting is influencing on Timestamp type value and doesn't affect Datetime type value.

How to repeat:
CREATE TABLE IF NOT EXISTS TST_Tbl (
    id BIGINT NOT NULL AUTO_INCREMENT,
    date1 DATETIME NOT NULL,
    date2 TIMESTAMP NOT NULL,
    PRIMARY KEY (id)
) ENGINE=NDBCLUSTER PARTITION BY KEY(id)
________________________________________
SELECT @@session.time_zone
+00:00
________________________________________
INSERT INTO TST_Tbl(date1,date2) VALUES(SYSDATE(),SYSDATE())
SELECT *,UNIX_TIMESTAMP(date1),UNIX_TIMESTAMP(date2) FROM TST_Tbl
id	date1	date2	UNIX_TIMESTAMP(date1)	UNIX_TIMESTAMP(date2)
1	2014-11-26 09:07:45	2014-11-26 09:07:45	1416992865	1416992865
________________________________________
SET @@session.time_zone = '+04:00'
SELECT *,UNIX_TIMESTAMP(date1),UNIX_TIMESTAMP(date2) FROM TST_Tbl
id	date1	date2	UNIX_TIMESTAMP(date1)	UNIX_TIMESTAMP(date2)
1	2014-11-26 09:07:45	2014-11-26 13:07:45	1416978465	1416992865
________________________________________
ALTER TABLE TST_Tbl MODIFY COLUMN date1 TIMESTAMP NOT NULL
ALTER TABLE TST_Tbl MODIFY COLUMN date2 DATETIME NOT NULL
SELECT *,UNIX_TIMESTAMP(date1),UNIX_TIMESTAMP(date2) FROM TST_Tbl
id	date1	date2	UNIX_TIMESTAMP(date1)	UNIX_TIMESTAMP(date2)
1	2014-11-26 09:07:45	2014-11-26 13:07:45	1416978465	1416992865

Suggested fix:
Update documentation or fix MySQL server
[10 Dec 2014 10:16] MySQL Verification Team
Hello Michael Prokopiv,

Thank you for the report.
Imho this difference is documented, quoting as per manual - "MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable. For more information, see Section 10.6, “MySQL Server Time Zone Support”."

please see http://dev.mysql.com/doc/refman/5.6/en/datetime.html

Thanks,
Umesh
[10 Dec 2014 12:49] Michael Prokopiv
ok, thanks!

And are you planning to change this behavior in some future or not?