Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get UTC value for SYSDATE on Oracle

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).

For now I've custom function :(

Cheers,

Stefan

like image 803
stic Avatar asked Jul 21 '09 08:07

stic


People also ask

Is Sysdate a UTC?

Returns the current timestamp for the system, but in the UTC time zone.

How can I get current date in UTC?

Current time: 03:29:55 UTC. UTC is replaced with Z that is the zero UTC offset. UTC time in ISO-8601 is 03:29:55Z. Note that the Z letter without a space.

What is Oracle UTC time?

SYS_EXTRACT_UTC extracts the UTC (Coordinated Universal Time--formerly Greenwich Mean Time) from a datetime value with time zone offset or time zone region name. Examples.

Does Oracle store TIMESTAMP in UTC?

This documentation for Oracle Database seems to say that TIMESTAMP WITH TIME ZONE type does record the incoming data's time zone or offset-from-UTC.


2 Answers

You can use

SELECT SYS_EXTRACT_UTC(TIMESTAMP '2000-03-28 11:30:00.00 -02:00') FROM DUAL; 

You may also need to change your timezone

ALTER SESSION SET TIME_ZONE = 'Europe/Berlin'; 

Or read it

SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM dual; 
like image 132
Jonathan Avatar answered Sep 28 '22 00:09

Jonathan


select sys_extract_utc(systimestamp) from dual; 

Won't work on Oracle 8, though.

like image 42
Juris Avatar answered Sep 28 '22 01:09

Juris