Oracle Timezone Conversion - oracle

I am using the inbuilt oracle function from_tz for timezone conversion. Does anyone know if it takes into account daylight saving changes?
to_char(from_tz(CAST(enteredondtm AS TIMESTAMP),'UTC')
AT TIME ZONE 'PST','YYYY-MM-DD') entered_on_date .
in this function the enteredondtm is in UTC which is converted to PST with this function. The conversion happens correctly. Just wanted to make sure it will happen during daylight savings.
Thanks.

Yes, it will take DST into consideration.
To convince yourself of that, substitute date '2018-02-01' for the column name enteredondtm in your formula and see what you get (use a full format model for TO_CHAR though, to see the time-of-day, not just the date). You will see that the output is 16:00 hours on the previous day. Then change that to date '2018-08-01' and you will see that the result is 17:00 hours on the previous day.
The date date literal has midnight as the time-of-day. During standard time, the Pacific time zone is eight hours behind UTC; during DST, it is seven hours behind.

Yes it does, simple proof:
SELECT
TIMESTAMP '2018-06-01 00:00:00 PST',
TIMESTAMP '2018-12-01 00:00:00 PST'
from dual;
01.06.2018 00:00:00 -07:00 01.12.2018 00:00:00 -08:00
However, why are you concerned about daylight savings if your output is YYYY-MM-DD, i.e. it does not contain any times?
Just a note, time zone PST can be ambiguous, see
SELECT TZABBREV, TZ_OFFSET(TZNAME), TZNAME
FROM V$TIMEZONE_NAMES
WHERE TZABBREV = 'PST';
TZABBREV TZ_OFFSET(TZNAME) TZNAME
========================================
PST -05:00 America/Bahia_Banderas
PST -06:00 America/Mazatlan
PST -06:00 America/Boise
PST -06:00 Mexico/BajaSur
PST -06:00 America/Inuvik
PST -07:00 America/Los_Angeles
PST -07:00 America/Hermosillo
PST -07:00 America/Ensenada
PST -07:00 America/Dawson_Creek
PST -07:00 America/Dawson
PST -07:00 America/Creston
PST -07:00 America/Santa_Isabel
PST -07:00 US/Pacific
PST -07:00 PST8PDT
PST -07:00 PST
PST -07:00 US/Pacific-New
PST -07:00 America/Tijuana
PST -07:00 America/Vancouver
PST -07:00 America/Whitehorse
PST -07:00 Canada/Pacific
PST -07:00 Canada/Yukon
PST -07:00 Mexico/BajaNorte
PST -08:00 America/Juneau
PST -08:00 America/Sitka
PST -08:00 Pacific/Pitcairn
PST -08:00 America/Metlakatla
Better use the "real" long name. There are only a few time zones (see SELECT * FROM V$TIMEZONE_NAMES WHERE TZABBREV = TZNAME) where you can use the abbreviation without getting a ORA-01882: timezone region not found error.

Related

Storing Tim in Database

I am trying to add the time with AM/PM into the database with 12HRS format but it is only storing the time like 10:10 or 13:45 and i need like 10:10 AM OR 3:45 PM etc.. like.
<input type="time" name="time">
$time=strtotime($_POST['appt']);
how i will insert like 10:10 AM OR 3:45 PM etc.. in database
how i will insert into database with 12 hrs format and with AM/PM

Show each month as a column in a table in PowerBI

I want to show in a table each month of ExaminationDate rather than just the year and month. For example, currently I have ExaminationDate in Field with Year and Month selected which shows:
Year Month
2021 January
2021 Febuary
2021 March
But how would I get it to display thusly:
Year January February March etc
2021 value
2021
2021

Convert UTC timestamp to AEDT in Oracle to consider daylight saving

Converting from UTC to AEST (Australian Eastern Standard Time) doesn't consider daylight saving as it's +11 hrs now, but this script still converts with 10 hrs :
Select from_tz (cast(DateField as TIMESTAMP),'UTC') at Time Zone 'Australia/Sydney' as AEST
Is there any intuitive way to make it 11 hours in Summer and 10 hours in winter without having to create a function and hard coding it?
Not sure how you determined that your formula "doesn't consider daylight savings". It does on my system. Note that the date literal assumes the time-of-day is midnight. Then compare:
select from_tz (cast(datefield as timestamp),'UTC')
at time zone 'Australia/Sydney' as aest
from ( select date '2020-07-31' as datefield from dual union all
select date '2020-12-15' from dual
)
;
AEST
------------------------------------
2020-07-31 10:00:00 Australia/Sydney
2020-12-15 11:00:00 Australia/Sydney
Obviously Oracle is aware of the difference between "summer" and "winter" times (DST adjustment).

Oracle SQL date getting first day of last quarter and last day of last quarter

I've been asked to provide an Oracle PL/SQL solution if a file is loaded into the system
for example between the dates of 1st Jan 2017 - 31st March 2017 I should
created two dates from the last quarter a loaded from date of
1st Oct 2016 and loaded to date of 31st Dec 2016. This should be future prove meaning it should work for future years, so if a file is loaded into the system lets say 21st August 2019, it should have a from date of 1st April 2019 and a to date of 30th June 2019.
This should be a PL/SQL solution most probably a procedure returning two dates to the main program and the to and from date returned should be in the format of DD/MM/YYYY.
Thanks in advance.
What about this solution?
SELECT
TO_CHAR(ADD_MONTHS(TRUNC(SYSDATE, 'Q'), -3), 'DD/MM/YYYY') AS output_from_date,
TO_CHAR(TRUNC(SYSDATE, 'Q')-1, 'DD/MM/YYYY') AS output_to_date
FROM dual;
OUTPUT_FROM_DATE OUTPUT_TO_DATE
01/04/2017 30/06/2017

oracle to_char daylight savings

In below, why isn't Daylight savings included in to_char()? How can i get the time with daylight savings?
SELECT systimestamp AT TIME ZONE 'Australia/Adelaide' from dual;
SELECT TO_CHAR(systimestamp AT TIME ZONE 'Australia/Adelaide' ,'yyyy-MM-dd HH:MI:SS AM') from dual;
returns
16-OCT-13 07.19.01.165681000 PM AUSTRALIA/ADELAIDE
2013-10-16 06:19:01 PM
select to_char( systimestamp at time zone 'AUSTRALIA/ADELAIDE',
'HH24:MI:SS TZR TZD' ) from dual
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34510
The issue was because of outdated timezones files in oracle server. Adelaide timezones were updated around 2008 or 2007. once timezone files were updated issue got resolved.

Resources