It is relatively easy to select current_timestamp from dual and get current date time in your time zone. But things get a little more complicated when you want to get date and time in a different time zone. Here is how you can accomplish that:
-- Get current date and time as well as current date and time in a different time zone (using eastern time zone).
SELECT CURRENT_TIMESTAMP currt_dt,
CURRENT_TIMESTAMP AT TIME ZONE TZ_OFFSET ('EST') different_dt
FROM DUAL;
CURRT_DT DIFFERENT_DT
----------------------------------- -----------------------------------
21-JUL-08 09.13.04.431522 AM -05:00 21-JUL-08 10.13.04.431522 AM -04:00
1 row selected.
-- Same as above but with no time zone display (-05:00)
SELECT LOCALTIMESTAMP currt_dt, LOCALTIMESTAMP AT TIME ZONE TZ_OFFSET ('EST') different_dt
FROM DUAL;
CURRT_DT DIFFERENT_DT
------------------------------- -----------------------------------
21-JUL-08 09.15.37.211514 AM 21-JUL-08 10.15.37.211514 AM -04:00
1 row selected.
And here is another one with better formatted time stamp.
SELECT TO_CHAR ((LOCALTIMESTAMP AT TIME ZONE TZ_OFFSET ('EST')),
'MM/DD/YYYY HH:MI:SS') different_zone_dt
FROM DUAL;
DIFFERENT_ZONE_DT
-------------------
07/21/2008 10:17:47
1 row selected.
A complete list of available time zones can be found by selecting from v$timezone_names table.
SELECT DISTINCT tzname
FROM v$timezone_names;
Bookmark/Search this post with:
Comments
Re: Get Current Time in a Different Time Zone
Join date: 06/30/08
If want to to same thing in PeopleSoft , this can help
DateTimeToTimeZone
DateTimeToTimeZone(OldDateTime, SourceTimeZone, DestinationTimeZone)
&NEWDATETIME = DateTimeToTimeZone(TESTDTTM, "PST", "EST");
Re: Get Current Time in a Different Time Zone
Join date: 06/23/08
Thanks Nitin, why not submit that as a Code Sample to your blog?! :)
Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog
Post new comment