Question

I am writing a procedure, where I get timezone offset from database and my requirement is to manipulate the local time with the timezone offset to get the UTC time.

For example,

If local time is   : 2/3/2013 2:05:53.000000 PM 
timezone offset is : 5:30
Output should be   : 2/3/2013 8:35:53.000000 AM (2/3/2013 2:05:53.000000 PM - 5:30)

Can anyone help me with appropriate function for this.

Was it helpful?

Solution 2

You can use FROM_TZ to form a TIMESTAMP WITH TIME ZONE value by combining a TIMESTAMP and a TIME ZONE. Next, use SYS_EXTRACT_UTC to convert it into UTC Time.

SQL> select from_tz(timestamp'2013-02-03 14:05:53','05:30'),
            sys_extract_utc(from_tz(timestamp'2013-02-03 14:05:53','05:30'))
     from dual;

FROM_TZ(TIMESTAMP'2013-02-0314:05:53','05:30')    SYS_EXTRACT_UTC(FROM_TZ(TIMESTAMP'2013-02-0314:05:53','05:30'))
------------------------------------------------- -----------------------------------------------------------------
03-FEB-13 02.05.53.000000000 PM +05:30            03-FEB-13 08.35.53.000000000 AM

OTHER TIPS

With Datetime Expressions you can do it even more generic:

SELECT FROM_TZ(TIMESTAMP '2013-02-03 14:05:53', '05:30') AT TIME ZONE 'UTC' 
FROM dual;

or

SELECT (TIMESTAMP '2013-02-03 14:05:53' AT TIME ZONE '05:30') AT TIME ZONE 'UTC' 
FROM dual;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top