Timestamp calculation with daylight saving time

只谈情不闲聊 提交于 2019-12-22 05:20:15

问题


The Central European Daylight Saving Time begins on last Sunday in March. We set our clocks from 02:00 to 03:00. What happens if I do timestamp calcuations in a database request - lets say at 01:59?

UPDATE sessions SET aliveuntil = (CURRENT_TIMESTAMP + INTERVAL '1' MINUTE) WHERE id = ?

Do I get 03:00 as result or 02:00?

And what about the over way around if we set our clocks from 03:00 to 02:00?

SELECT id FROM sessions WHERE aliveuntil < (CURRENT_TIMESTAMP - INTERVAL '1' MINUTE)

After time changed from 03:00 to 02:00... what happens with the (CURRENT_TIMESTAMP - INTERVAL '1' MINUTE) at 02:00? Is it 02:59 or 01:59?

How should this be handled? Best practice and how it's handle (in my particular case) by Oracle Database 11g Release 11.2.0.2.0?


回答1:


If I'm understanding their documentation correctly, it depends on how the table/columns are setup in the database. If the columns are setup to use WITH TIME ZONE, then Oracle automatically determines the correct/relevant values. In your above example if the column aliveuntil has this setting, then if you try to add 1 minute at 1:59, the time will update to 3:00.

Here is a helpful article I found on the subject:

http://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm

Scroll down to the bottom of the article and you should see what you're looking for.

Here was a section of the article I found relevant:

For example, in the Eastern region of the United States, the time changes from 01:59:59 a.m. to 3:00:00 a.m. when Daylight Saving Time goes into effect. The interval between 02:00:00 and 02:59:59 a.m. does not exist. Values in that interval are invalid.



来源:https://stackoverflow.com/questions/14157708/timestamp-calculation-with-daylight-saving-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!