How to get UTC value for SYSDATE on Oracle

后端 未结 5 1123
耶瑟儿~
耶瑟儿~ 2020-12-05 04:03

Probably a classic... Would you know a easy trick to retrieve an UTC value of SYSDATE on Oracle (best would be getting something working on the 8th version as well).

5条回答
  •  爱一瞬间的悲伤
    2020-12-05 04:36

    Usually, I work with DATE columns, not the larger but more precise TIMESTAMP used by some answers.

    The following will return the current UTC date as just that -- a DATE.

    CAST(sys_extract_utc(SYSTIMESTAMP) AS DATE)
    

    I often store dates like this, usually with the field name ending in _UTC to make it clear for the developer. This allows me to avoid the complexity of time zones until last-minute conversion by the user's client. Oracle can store time zone detail with some data types, but those types require more table space than DATE, and knowledge of the original time zone is not always required.

提交回复
热议问题