Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timezone conversion in PLSQL

I need to convert the sysdate and time to a particular timezone like EST. I can't assume my current time zone.

How to convert this in plsql? Please help me.

like image 374
Suvonkar Avatar asked Apr 26 '12 07:04

Suvonkar


People also ask

How check timezone in PL SQL?

I just ran select systimestamp from dual; in SQL developer on my machine, it replied with 30-MAY-16 12.49. 28.279000000 PM -05:00 . The -05:00 shows the timezone offset (5 hours behind UTC, essentially 5 hours behind GMT with no daylight savings time adjustments made to GMT). This shows the database server time zone.

How do I change timezone in Oracle?

Best Answer. SELECT SYSTIMESTAMP AS Phoenix_TZ ,CAST(SYSTIMESTAMP AT TIME ZONE 'America/New_York' AS TIMESTAMP WITH TIME ZONE) AS NY_TZ FROM dual; Hope this helps.

What is the use of timezone in Oracle?

Use the ALTER DATABASE SET TIME_ZONE command to change the time zone of a database. This command takes either a named region such as America/Los_Angeles or an absolute offset from UTC. This example sets the time zone to UTC: ALTER DATABASE SET TIME_ZONE = '+00:00';


1 Answers

Assuming you have a TIMESTAMP WITH TIME ZONE (such as systimestamp), you can use the AT TIME ZONE syntax. For example, I can take the current systimestamp and convert it to UTC (GMT), Eastern, and Pacific time zones by specifying different time zone names.

SQL> ed
Wrote file afiedt.buf

  1  select systimestamp at time zone 'UTC' current_time_in_utc,
  2         systimestamp at time zone 'Us/Eastern' current_time_in_est,
  3         systimestamp at time zone 'US/Pacific' current_time_in_pst
  4*   from dual
SQL> /

CURRENT_TIME_IN_UTC
---------------------------------------------------------------------------
CURRENT_TIME_IN_EST
---------------------------------------------------------------------------
CURRENT_TIME_IN_PST
---------------------------------------------------------------------------
26-APR-12 05.36.11.802000 PM UTC
26-APR-12 01.36.11.802000 PM US/EASTERN
26-APR-12 10.36.11.802000 AM US/PACIFIC
like image 120
Justin Cave Avatar answered Sep 23 '22 01:09

Justin Cave