Search code examples
sqloracle-databaseoracle11gtimestamp-with-timezone

Oracle. Correct offset in timestamp with timezone


I'm executing this select now

SELECT FROM_TZ(to_timestamp('2015-08-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss'),'Asia/Singapore') AT TIME ZONE 'UTC'
FROM DUAL

I'm interesting in time, in this case time is 02:00 AM, because Singapore has difference between UTC in 8 hours.
Everything is ok, but, if I'm changing month from 08 to 01, I'm expecting to get 03:00 AM, because it was winter time in Singapore, but I get 02:00 AM again.
So the question is, how could I get the correct result with correct offset?


Solution

  • Asia/Singapore does not have any Daylight saving times, see here: Singapore Standard Time

    Crazy, Oracle implemented this list properly:

    SELECT FROM_TZ(TO_TIMESTAMP('2015-01-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'Asia/Singapore') AS TS FROM DUAL;
    TS                                      
    ----------------------------------------
    08.01.2015 10:00:00.000000000 +08:00    
    1 row selected.
    
    SELECT FROM_TZ(TO_TIMESTAMP('1970-01-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'Asia/Singapore') AS TS FROM DUAL;
    TS                                      
    ----------------------------------------
    08.01.1970 10:00:00.000000000 +07:30    
    1 row selected.
    
    SELECT FROM_TZ(TO_TIMESTAMP('1943-01-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'Asia/Singapore') AS TS FROM DUAL;
    TS                                      
    ----------------------------------------
    08.01.1943 10:00:00.000000000 +09:00    
    1 row selected.
    
    SELECT FROM_TZ(TO_TIMESTAMP('1940-01-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'Asia/Singapore') AS TS FROM DUAL;
    TS                                      
    ----------------------------------------
    08.01.1940 10:00:00.000000000 +07:20    
    1 row selected.
    
    SELECT FROM_TZ(TO_TIMESTAMP('1920-01-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'Asia/Singapore') AS TS FROM DUAL;
    TS                                      
    ----------------------------------------
    08.01.1920 10:00:00.000000000 +07:00    
    1 row selected.