To preserve accuracy with DATETIME or TIMESTAMP values, use UNIX_TIMESTAMP( ) and FROM_UNIXTIME( ) instead.
mysql>
mysql> SET @dt = '2002-01-01 09:00:00';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @dt AS datetime,
-> FROM_UNIXTIME(UNIX_TIMESTAMP(@dt) + 3600) AS 'datetime + 1 hour',
-> FROM_UNIXTIME(UNIX_TIMESTAMP(@dt) - 3600) AS 'datetime - 1 hour';
+---------------------+---------------------+---------------------+
| datetime | datetime + 1 hour | datetime - 1 hour |
+---------------------+---------------------+---------------------+
| 2002-01-01 09:00:00 | 2002-01-01 10:00:00 | 2002-01-01 08:00:00 |
+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
mysql>
Related examples in the same category