I created the following function to convert the GMT to your local time. Note that I'm using Oracle 8.1.7, and am in the central time zone. You will need to convert the timezones for your situation. Also, note that it checks for Daylight savings time. Once again, you may need to adjust:
function convert_gmt(check_date date)
return date is
start_dst date; - date for start of daylight savings time
end_dst date; - date form end of daylight savings time
start_sunday integer; - day of the month for first Sunday in April
end_sunday integer; - day of the month for last Sunday in October
year varchar2(5); - current year
begin
year := to_char(check_date, 'YYYY'); - Get year for the given date.
- compute the date of the first Sunday in April for the given year.
start_sunday := mod(8 to_number(to_char(to_date('01APR'||year,'DDMONYYYY'),'D')),7) + 1;
-dbms_output.put_line('start_sunday = ' || start_sunday);
- compute the date of the last Sunday in October for the given year.
end_sunday := 31 to_number(to_char(to_date('31OCT'||year,'DDMONYYYY'),'D')) + 1;
-dbms_output.put_line('end_sunday = ' || end_sunday);
- Compute the actual start dates and times for daylight savings time begin and end
start_dst := to_date(to_char(start_sunday,'00')||'APR'||year||' 02:00:00 AM','DDMONYYYY HH:MI:SS AM');
end_dst := to_date(to_char(end_sunday,'00')||'OCT'||year||' 02:00:00 AM','DDMONYYYY HH:MI:SS AM');
- Check if daylight savings time is in effect
if(check_date >= start_dst and check_date < end_dst) then
return new_time(check_date, 'GMT', 'CDT');
else
return new_time(check_date, 'GMT','CST');
end if;
end convert_gmt;