By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select version();
version() |
---|
5.7.35 |
SELECT @@session.time_zone, NOW();
--
-- As of 27/12/2021, the db<>fiddle server uses the SYSTEM timezone which, given that
-- it's located in Britain is either UTC (in winter) or UTC+1 (summer). So, setting a
-- timezone of +07 should give clear blue water between the zones for the purposes of
-- this test. The example given of Utah in the US should retain a 7 hour difference
-- because, for the moment at least, they also have Daylight Savings Time (DST)
--
@@session.time_zone | NOW() |
---|---|
SYSTEM | 2022-05-09 18:22:57 |
SET time_zone = "+07:00";
SELECT @@session.time_zone, NOW();
@@session.time_zone | NOW() |
---|---|
+07:00 | 2022-05-10 00:22:57 |
CREATE TABLE testx
(
d DATETIME,
t TIMESTAMP(6)
);
INSERT INTO testx VALUES (NOW(6), NOW(6));
SELECT * FROM testx;
d | t |
---|---|
2022-05-10 00:22:58 | 2022-05-10 00:22:57.562008 |
SET time_zone = "+00:00";
SELECT
UNIX_TIMESTAMP(d) AS "DateTime", UNIX_TIMESTAMP(t) AS "TimeStamp",
UNIX_TIMESTAMP(NOW(6)) AS "Now",
SEC_TO_TIME(UNIX_TIMESTAMP(d) - UNIX_TIMESTAMP(NOW())) AS "DT diff", -- = 7 hours (+ rounding)
SEC_TO_TIME(UNIX_TIMESTAMP(t) - UNIX_TIMESTAMP(NOW())) AS "TS diff", -- few deciseconds
FROM_UNIXTIME(UNIX_TIMESTAMP(t)) AS "Now wall time here", -- = queries above
FROM_UNIXTIME(UNIX_TIMESTAMP(d)) AS "Now wall +7 (e.g. Utah, US relative to UTC)
\nSmall rounding difference?"
FROM testx;
DateTime | TimeStamp | Now | DT diff | TS diff | Now wall time here | Now wall +7 (e.g. Utah, US relative to UTC) Small rounding difference? |
---|---|---|---|---|---|---|
1652142178 | 1652116977.562008 | 1652116977.564732 | 07:00:01 | 00:00:00.562008 | 2022-05-09 17:22:57.562008 | 2022-05-10 00:22:58 |