Goal
Retrieve the date values based on session time zone instead of database or server time zone.
Solution
Convert the date values from data base / server time zone to Session time zone.
Date Time
The datetime datatypes are DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE.
TIMESTAMP WITH TIME ZONE also includes these fields:
- TIMEZONE_HOUR
- TIMEZONE_MINUTE
- TIMEZONE_REGION
- TIMEZONE_ABBR
TIMESTAMP WITH LOCAL TIME ZONE does not store time zone information internally, but you can see local time zone information in SQL output if the TZH:TZM or TZR TZD format elements are specified.
Date Time Stamp SQL Functions
1. SYS_EXTRACT_UTC
Purpose
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. If a time zone is not specified, then the datetime is associated with the session time zone.
Examples
The following example extracts the UTC from a specified datetime:
SQL1
SELECT SYS_EXTRACT_UTC(TIMESTAMP '2019-04-01 11:30:00.00 -07:00') NEW_VALUE
FROM DUAL;
SQL1 Output
2. FROM_TZ
Purpose
FROM_TZ converts a timestamp value and a time zone to a TIMESTAMP WITH TIME ZONE value. TIME_ZONE_VALUE is a character string in the format 'TZH:TZM' or a character expression that returns a string in TZR with optional TZD format.
Examples
The following example returns a timestamp value to TIMESTAMP WITH TIME ZONE:
SQL2
SELECT FROM_TZ(TIMESTAMP '2018-04-01 11:30:00', '-7:00') NEW_VALUE
FROM DUAL;
SQL2 Output
3. NEW_TIME
Purpose
NEW_TIME returns the date and time in time zone timezone2 when date and time in time zone timezone1 are date. Before using this function, you must set the NLS_DATE_FORMAT parameter to display 24-hour time. The return type is always DATE, regardless of the datatype of date.
Examples
The following example returns a Mountain Day Light Saving Time, given the Greenwich Mean Time equivalent:
SQL3
SELECT SYSDATE GMT_SYSDATE,
NEW_TIME(SYSDATE, 'GMT', 'MDT') MDT_SYSDATE
FROM DUAL;
SQL3 Output
SYSDATE (User Time Zone) SQL
SQL4
SELECT TO_CHAR(NEW_TIME(SYSDATE, 'GMT', TO_CHAR( FROM_TZ (SYS_EXTRACT_UTC (SYSTIMESTAMP),'UTC') AT TIME ZONE FND_PROFILE.VALUE ('FND_TIMEZONE'),'TZD')), 'MM-DD-YYYY') SYSDATE_SESSION_TZ
FROM DUAL
SQL5
SELECT SYSDATE SYSDATE_TIMESTAMP_SERVER,
TO_CHAR(SYSDATE, 'MM-DD-YYYY') SYSDATE_SERVER,
FND_PROFILE.VALUE('FND_TIMEZONE') FND_TZ,
TO_CHAR(FROM_TZ(SYS_EXTRACT_UTC(SYSTIMESTAMP),'UTC') AT TIME ZONE FND_PROFILE.VALUE('FND_TIMEZONE'),'TZD') SESSION_TZ,
TO_CHAR(NEW_TIME(SYSDATE, 'GMT', TO_CHAR(FROM_TZ(SYS_EXTRACT_UTC(SYSTIMESTAMP),'UTC') AT TIME ZONE FND_PROFILE.VALUE('FND_TIMEZONE'),'TZD')), 'MM-DD-YYYY') SYSDATE_SESSION_TZ
FROM DUAL
SQL5 Output
Oracle Support Documents
- How to Find User Time Zone (Doc ID 2348229.1)
- Timestamps & Time Zones - Frequently Asked Questions (Doc ID 340512.1)
- Fusion Core HR : HCM OTBI Time Zone Issue (Doc ID 2517748.1)
- Export Manage Admin Profile Value For FND_TIMEZONE (Doc ID 2262334.1)
- TSLTZ (TIMESTAMP WITH LOCAL TIME ZONE) Data and DST Updates (Doc ID 756454.1)
- Fusion BI Publisher: Need local time as report run time in BI Publisher report but it shows UTC time zone (Doc ID 2168341.1)