How to convert sysdate to UTC time in oracle

Shubham Khatri picture Shubham Khatri · Oct 18, 2016 · Viewed 10.3k times · Source

I am having a query to subtract a date from the sysdate. However the date object I have is in UTC but sysdate doesn't give me UTC time. How to I convert sysdate to give me date in UTC.

I have already tried using sys_extract_utc

select sys_extract_utc(systimestamp) from dual;

This works fine and gives me the correct UTC time stamp. But the object returned by it is not the same as sysdate so when I subtract date from this object I get an INTERVAL DAY to SECOND but it should be a number.

Answer

Shubham Khatri picture Shubham Khatri · Oct 18, 2016

Using CAST on the result of sys_extract_utc(systimestamp) is the solution to this since sys_extract_utc returns timestamp.

select cast(sys_extract_utc(systimestamp) as DATE) from dual;