Converting UTC dates to local time

Hello all. I have some data I imported that has a date column containing dates spanning a number of years. The dates are in the UTC timezone.
I need to display the dates in the local time zone that was in effect at the time. I've seen many fine examples of converting from one time zone to another. But I need it to be smarter than that. For example, date/times (this year) prior to 03/09/2008 2AM should display in EST (my zone in effect then), while date/times on/after then should display in EDT.
Are there any Oracle built-in functions to do this, or will I need to gather the data of when daylight savings time begins/ends for the years I have dates and write my own function? I don't need help for the latter; I just don't want to reinvent the wheel. Also, I don't want to convert the data; I append to it regularly.
Thanks for your help and consideration.

Sergiusz, thanks again. When I added a very recent date, I saw the effect. But perhaps something is wrong with my local 10gR1 "play" database. It seems the DST start point is not correct. Should it not start showing -4 offset at row# 4? I didn't see a change until I added the last date. But I believe DST began on 3/9/2008 at 2am local, which is 7am UTC.
~Pete
SQL> DROP   TABLE imported_events;
Table dropped.
SQL> CREATE TABLE imported_events (event_date TIMESTAMP(0) WITH TIME ZONE);
Table created.
SQL> BEGIN
  2  INSERT INTO  imported_events VALUES ( '10-JAN-08 2:00:00 PM UTC');
  3  INSERT INTO  imported_events VALUES ( '08-MAR-08 2:00:00 PM UTC');
  4  INSERT INTO  imported_events VALUES ( '09-MAR-08 6:59:00 AM UTC');
  5  INSERT INTO  imported_events VALUES ( '09-MAR-08 7:01:00 AM UTC');
  6  INSERT INTO  imported_events VALUES ( '09-MAR-08 2:00:00 PM UTC');
  7  INSERT INTO  imported_events VALUES ( '10-MAR-08 2:00:00 PM UTC');
  8  INSERT INTO  imported_events VALUES ( '09-JUN-08 2:00:00 PM UTC');
  9  COMMIT;
10  END;
11  /
PL/SQL procedure successfully completed.
SQL> COLUMN ROWNUM         FORMAT 99
SQL> COLUMN event_date_utc FORMAT A25
SQL> COLUMN offset_local   FORMAT 99
SQL> COLUMN offset_eastern FORMAT 99
SQL> SELECT ROWNUM
  2        ,event_date event_date_utc
  3        ,TO_CHAR(CAST((event_date AT LOCAL) AS DATE),'YYYY-MM-DD HH24:MI:SS') date_local
  4        ,(CAST((event_date AT LOCAL) AS DATE) - CAST(event_date AS DATE))*24 offset_local
  5        ,TO_CHAR(CAST((event_date AT TIME ZONE 'US/Eastern') AS DATE),'YYYY-MM-DD HH24:MI:SS') date_eastern
  6        ,(CAST((event_date AT TIME ZONE 'US/Eastern') AS DATE) - CAST(event_date AS DATE))*24 offset_eastern
  7    FROM imported_events
  8   ORDER BY 1;
ROWNUM EVENT_DATE_UTC            DATE_LOCAL          OFFSET_LOCAL DATE_EASTERN        OFFSET_EASTERN
     1 10-JAN-08 02.00.00 PM UTC 2008-01-10 10:00:00           -4 2008-01-10 09:00:00             -5
     2 08-MAR-08 02.00.00 PM UTC 2008-03-08 10:00:00           -4 2008-03-08 09:00:00             -5
     3 09-MAR-08 06.59.00 AM UTC 2008-03-09 02:59:00           -4 2008-03-09 01:59:00             -5
     4 09-MAR-08 07.01.00 AM UTC 2008-03-09 03:01:00           -4 2008-03-09 02:01:00             -5
     5 09-MAR-08 02.00.00 PM UTC 2008-03-09 10:00:00           -4 2008-03-09 09:00:00             -5
     6 10-MAR-08 02.00.00 PM UTC 2008-03-10 10:00:00           -4 2008-03-10 09:00:00             -5
     7 09-JUN-08 02.00.00 PM UTC 2008-06-09 10:00:00           -4 2008-06-09 10:00:00             -4
7 rows selected.
SQL>

Similar Messages

  • ABAP statement for converting UTC date/ time to local date/time

    Hi
    Is there any abap statement or any function module in BW which converts UTC date and UTC
    time into local date and local time according to specific country.
    Regards,
    Kate

    Hi,
    and to convert the country to a timezone first use: TZ_LOCATION_TIMEZONE
    /manfred

  • I have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    i have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    What does this have to do with iPhone tech support?

  • Datetime of Records UTC vs. Local Time

    Hi, I notice that the Integrator automatically converts the datetime of records to UTC upon insertion. In Studio however, we want the analysis / records to reflect our local time instead. The Endeca Server Data Loading Guide http://docs.oracle.com/cd/E37502_01/server.751/es_data_loading/toc.htm#dateTime%20property mentions about the possibility of updating a record with two datetime properties. How is this achieved using Integrator? My records seem to be converted automatically into UTC even when I append the timezone. Thanks!

    I'm afraid this explanation doesn't quite address the question... but it's close.
    The real question is what "based on UTC time" means, vs. "UTC time"
    Assume your SCCM server is set to deploy the update at 8PM UTC, but Windows time on your SCCM server (due to the time zone it is in) is configured for UTC-2, which is 6PM when "true" UTC is at 8PM.  When does the update happen?  8PM (true
    UTC time), or 6PM (SCCM server time "based on" UTC", which includes the offset)?  I understand that all target servers will deploy simultaneously (since we selected UTC instead of local), but is that simultaneous time "true" UTC,
    or the SCCM server UTC +/- offset?

  • Converting UTC time stamp to local time (CET)

    Is there a smooth way to convert a time stamp from UTC time into the local time (e.g. CET)?
    CONVERT TIME STAMP.... Just converts the timestamp from local time zone to UTC, is there another comand to perform the opposite conversion?
    TIA!
    /Armin

    Hi Armin
    The statement does not only convert from local time zone to UTC you can specifiy any timezone:
    CONVERT TIME STAMP time_stamp TIME ZONE tz
            INTO [DATE dat] [TIME tim]
            [DAYLIGHT SAVING TIME dst].
    The following statement can also be used to convert from date time to timestamp.
    CONVERT DATE dat [TIME tim [DAYLIGHT SAVING TIME dst]]
            INTO TIME STAMP time_stamp TIME ZONE tz.
    Regards
    Faaiez

  • Converting timestamp from local time to UTC

    Is there a smooth way to convert a timestamp containing local time to UTC time?
    The statement:
    CONVERT TIME STAMP time_stamp TIME ZONE tz
    INTO [DATE dat] [TIME tim]
    [DAYLIGHT SAVING TIME dst].
    Consideres time_tamp to be UTC time and then tries to convert it to the time zone specified in tz. What I would like to have done is the opposite, to have time_stamp represent the local time and then convert it back to UTC.
    TIA!
    /Armin

    Hi Armin.
    Just turn your statement and you will be fine
    DATA: date TYPE sydatum VALUE '20070525',
          time TYPE syuzeit VALUE '173030',
          cet  TYPE tzonref-tzone VALUE 'CET',
          utc  TYPE tzonref-tzone VALUE 'UTC',
          tstp TYPE timestamp.
    CONVERT DATE date TIME time INTO TIME STAMP tstp TIME ZONE cet .
    The output will be 15:30:30 at 25th of May 2007.
    I used CET as example, just use the timezone your date is representing. The result is formatted as UTC.
    Actually if you only have the timestamp, for this solution you have to convert it into date/time first.
    Use
    CONVERT TIME STAMP tstp TIME ZONE utc INTO DATE date TIME time.
    to do so.
    Regards,
    Timo.

  • Convert Data time stamp to Local Time

    Hello,
    I want to convert this input to local time EST.
    Input:12/8/2006 10:23:00.000000000 PM -06:00
    o/p: EST.Local Time

    Is the input a string? A timestamp? If so, which flavor of timestamp? Something else?
    Normally, you'd want to use a TIMESTAMP WITH LOCAL TIME ZONE data type for this sort of requirement, since it automatically converts data to the client's time zone. Assuming the input is a string and that the client's time zone is set to EST
      1  select cast(to_timestamp_tz( '12/8/2006 10:23:00.000000000 -06:00',
      2                               'MM/DD/YYYY HH24:MI:SS.FF TZH:TZM' )
      3                AS TIMESTAMP WITH LOCAL TIME ZONE)
      4*   from dual
    SCOTT @ nx102 JCAVE9420> /
    CAST(TO_TIMESTAMP_TZ('12/8/200610:23:00.000000000-06:00','MM/DD/YYYYHH24:MI
    08-DEC-06 11.23.00.000000 AM
    Elapsed: 00:00:00.01
    SCOTT @ nx102 JCAVE9420> Justin

  • UTC Date/Time conversion

    Is there a documented formula for converting UTC date/time stamps in CallDetailRecords (e.g., 1074902387) to a recognizable time/date?

    In Call Manager, the CDR exports are in EPOCH time. Here is the  formula to convert epoch time in a Call Manager CDR to a standard format  in excel. After using the formula, you will need to format the cell for  date and time.
    =(((E2-(6*3600))/86400)+25569)
    E2 = cell reference
    6 = Timezone Offset (this is Central Standard time)
    3600 = Number of seconds in an hour
    86400 = Number of seconds in a day
    25569 = Excel hack because excel counts epoch from 1/1/1904 and most others start at 1/1/1970.
    Found this formula on the following webpage:
    http://ciscovoiceguru.com/473/convert-epoch-utc-time-in-excel/

  • Why Date() return local and GMT time intermixturely

    I have following code in my Java application:
    Date dt = new Date();
    System.out.println("Local Time: " + dt.toString());
    I got local date (CST) at most time. But I got GMT format date few times within hours' running by the same code and the same running, which will crash my DateFormate later.
    Can anyone tell me why this happened? Is there any way I may use to make sure of that "new Date() will return only one date format, local or GMT"?
    Thanks.

    Do appreciate of your reply. In my application, I do use new Date() and DateFormat.format() like you suggested. But I caught following exception. Then I use Date.toString() to test Date and found that " new Date() return local time (CST time) and GMT time intermixturely". Most time, my application got CST time string and my SimpleDateFormat("yyyy.MM.dd' 'HH:mm:ss:SSS") works well. But few times a running, new Date() return a GMT time string, then I got following exception. I was confused by why one statement "Date dt = new Date();" in one running return both CST and GMT time.
    java.lang.IllegalArgumentException
         at java.util.SimpleTimeZone.getOffset(SimpleTimeZone.java:427)
         at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:1173)
         at java.util.Calendar.complete(Calendar.java:1058)
         at java.util.Calendar.get(Calendar.java:916)
         at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:481)
         at java.text.SimpleDateFormat.format(SimpleDateFormat.java:410)
         at java.text.DateFormat.format(DateFormat.java:305)

  • Is there any way to set the SCCM system to use local time instead of UTC?

    We have ConfigMgr 2012 in our environment. We are in EST.
    Is there any way to set the SCCM system to use local time instead of UTC?
    When we try to deploy packages, if you don’t specify the time, it reverts to UTC which for us is off by 5 hours.

    Which times are you talking about? Deployment start times or deadlines? Those could be set to UTC *or* client local time.
    Torsten Meringer | http://www.mssccmfaq.de

  • Local time

    Let's say I have a function with a signature like this: private function (date:Date) {     trace(date.datetime); } ... when I send a date value into this function does the time portion gets converted into local time automatically?  Thanks

    I think you are describing a classic date management problem that has no single good solution.  The problem is that if you store dates in local time and don’t store timezone information, you don’t have enough data to view the date as desired on other clients especially if they are in other time zones.  You will find other past discussions on this topic.
    The basic problem is that, if you have, say, a west coast office and an east coast office and the west coast office records a transaction at 9am and stores it as 9am, the east coast office doesn’t know whether it happened at 9am their time or 12pm their time.  There is another version of the problem where things are stored in GMT but you really want to reproduce the local time display at the office that made the transaction.
    One solution offered is to not use date/time and simply use a string.  Otherwise, you have to know which office made the transaction and what time zone it is in.

  • HELP - How to Convert Date in GMT to Local time in Applet

    Hi All
    Is there a way to convert a date from GMT format into a local time say IST in my Java applet, this GMT date is coming from a postgresql database.
    Thanks in advance
    Swaraj

    Try this with your customization:
    java.text.SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.text.SimpleDateFormat format1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    java.util.Calendar cal0 = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    java.util.Calendar cal1 = Calendar.getInstance(new SimpleTimeZone((int)(5.5*60*60*1000), "IST"));
    format0.setCalendar(cal0);
    format1.setCalendar(cal1);
    java.util.Date date = format0.parse("2003-01-25 00:15:30");
    java.lang.String formatted = format1.format(date);
    System.out.println(formatted);

  • Power Query Language Functions to Convert a UTC Date/Time to MST

    I need to convert an implicit UTC date/time value to a MST date/time value.  I thought that I could achieve this by converting to an ISO 8601 compliant text representation of the MST date/time value (see below) and then back to a date/time value, but
    it's not working ...
    DateTime.FromText( DateTime.ToText( [MIN_REVSN_RLSE_DTTM] ,"yyyy-MM-ddThh:mm:ss-07")) 
    Is this a bug?  Or, is there a better way to do this?

    That's a fixed duration. Why not just [MIN_REVSN_RLSE_DTTM] + #duration(0, -7, 0, 0)?
    EDIT: For what it's worth, I don't think PQ ever does anything with DST anyway. This has both good points and bad points.

  • Converting UNIX time stamp to local time using T- SQL

    Hi All,
    I am getting DateTime in UTC time (UTC time (Coordinated Universal Time or Greenwich Mean Time))  using (datediff(ss, '1/1/1970', current_timestamp)) . I want to Convert this in my Local DateTime (CST DateTime). How to achieve this in simple way in T-SQL.
    thanks,
    Venkat

    Imports System.Data.SqlTypes
    Imports System
    Imports System.Data
    Imports System.Data.SqlClient
    Imports Microsoft.SqlServer.Server
    Partial Public Class UserDefinedFunctions
        'Microsoft.SqlServer.Server.SqlFunction(IsDeterministic=false)
        <SqlFunction()> _
        Public Shared Function displayLocalTime(dt As SqlDateTime) As SqlDateTime
            If (dt.IsNull) Then
                Return dt
            End If
            Return TimeZone.CurrentTimeZone.ToLocalTime(dt.Value)
        End Function
    End Class
    Apply it to SQL Server and use in SELECT statement
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Conversion between local time and UTC: Anomaly at Daylight saving time edge

    Hi all,
    I want to convert back and forth between local time including all peculiarities like DST etc. This is the core of my code:
        Date d=new Date(toEpoch());
        Calendar cal=Calendar.getInstance(tz);
        cal.setTime(d);
        int offs=(cal.get( Calendar.ZONE_OFFSET )+cal.get( Calendar.DST_OFFSET ));
        System.out.println("zone_offset: "+cal.get( Calendar.ZONE_OFFSET )+", dst_offset: "+cal.get( Calendar.DST_OFFSET )+", offset: "+offs);
        Calendar cal2=Calendar.getInstance(TimeZone.getTimeZone("Etc/UTC"));
        System.out.println(cal2.getTimeZone().getID());
        cal2.setTime(d);
        cal2.add(Calendar.MILLISECOND,-offs);
        d=cal2.getTime();Looks (and, actually, is) rather complicated. I take two different calendar objects to be absolutely sure that no accidental DST conversion hits me on the UTC side.
    The general case works as expected:
    Date (fourteen digits, 'x'=Exit): 20050909190000
    Entered date: Fr, 9.9.2005, 19:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Etc/UTC
    Date in UTC:  Fr, 9.9.2005, 17:00I live in timezone Europe/Berlin, so during DST we have GMT+2. Let's see what's happening on christmas (non-DST):
    Date (fourteen digits, 'x'=Exit): 20051224180000
    Entered date: Sa, 24.12.2005, 18:00
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Etc/UTC
    Date in UTC:  Sa, 24.12.2005, 17:00As expected!
    Now, we enter the dark zone of DST: Each year DST is turned on and off and it seems as if this leads to problems in both cases. Let's start with the next event of this case: At Oct., 30th, 2005, DST is turned off between 2:00 and 3:00 at night. So, we have once 2:30 with DST and (one hour later) 2:30 again without DST. Java, however, garbles things completely (I'm leaving the unneeded lines of my debug output out now):
    Entered date: So, 30.10.2005, 01:59
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  Sa, 29.10.2005, 23:59
    Entered date: So, 30.10.2005, 02:00
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:00
    Entered date: So, 30.10.2005, 02:30
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:30
    Entered date: So, 30.10.2005, 02:59
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:59
    Entered date: So, 30.10.2005, 03:00
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:00So, directly before the DST change, offset is computed correctly. From 3:00 onward, also. But in between, Calendar does neither take an offset of two hours (what would be somehow correct) nor one hour (also somehow correct). Even though it predicts to take the one-hour zone offset into consideration, "GMT" time is actually the same as local time.
    Things become even wireder at the other edge of the DST time range: This year, DST began on March, 27th, 2005: Let's see what is happening:
    Entered date: So, 27.3.2005, 01:59
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 27.3.2005, 00:59
    Entered date: So, 27.3.2005, 02:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:00
    Entered date: So, 27.3.2005, 02:30
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:30
    Entered date: So, 27.3.2005, 02:59
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:59
    Entered date: So, 27.3.2005, 03:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:00
    Entered date: So, 27.3.2005, 04:59
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 01:59
    Entered date: So, 27.3.2005, 05:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 03:00While at 1:59, everything is ok, 2:00 is handled as within DST. That's ok, as the hour between 2:00 and 3:00 did not exist in that night in our local time zone, but at 3:00 the system totally screws up things as it suddenly subtracts three hours (while pretending to use two hours). This goes on until 5:00 in the morning when time is shown correctly again.
    Can anyone help me? What am I doing wrong? How do I actually convert correctly between a DST-aware local time zone and GMT/UTC?
    Best regards,
    Dirk

    Well, I would not say I did "just about everything" wrong. Actually, Calendar is not GMT-only as it has time zone information and converts its internal time according to that information if I use the getTime() function (what I do).
    In my applications, I handle dates in my own data structures. My EDate object (which is part of the QJCC library hosted on SourceForge) stores years, months, days, minutes, hours, and seconds seperately. Using this class, I managed to get an actually working time zone conversion this way:
      public void toUTC(TimeZone tz) {
        Calendar cal=Calendar.getInstance(tz);
        cal.clear();
        cal.set(year,month-1,day,hour,minute,second);
        int offs=(cal.get( Calendar.ZONE_OFFSET )+cal.get( Calendar.DST_OFFSET ));
        //System.out.println("zone offset: "+cal.get( Calendar.ZONE_OFFSET )+", DST offset: "+cal.get( Calendar.DST_OFFSET ));
        second-=(offs/1000);
        normalize();
    normalize() does something similar to the lenient stuff in Calendar.
    I will now write the method for the other direction. The most interesting item will be the answer to the question:
    "Tell me the correct DST_OFFSET in TimeZone X when I have the actual point of time given in UTC."
    Perhaps someone can give me a hint?!?

Maybe you are looking for

  • Help with PDF form responses

    Hey there! I have two issues with online form data collection and am completely stumped. It's a real struggle to find useful documentation for Acrobat forms! #1 - I have created a form uploaded it to Acrobat.com, and have been able to collect test fo

  • Extensions not appearing in Photoshop CC

    Problem Additional extensions aren't appearing in the photoshop CC Window > Extension menu. The default Kuler extensions is there and active but manually installed extensions aren't. I'm trying to install the "Web Zap plugin". It works on my PC at ho

  • Where can I buy an iPhone5 Charger today?

    I left mine at a friends house and my battery is dead. No apple stores have ANY in stock! My only option is using the chargers for the display iPhone5's at the apple store =|    I'm def. not happy.

  • Loupe and Grid view rendering not as good as Develop view.

    I recently see that while using LR 5.6 the images rendered in the loupe and grid views do not look nearly as good as the same image displayed in the develop view.  I have screen grabs if you'd like to see them below.  The Loupe and grid are not as sa

  • Sage-mathematics from AUR fails to build

    Anyone have any ideas why eclib shared libraries failed to build. I'd like to get the program running quickly, as I'm using it for college. On an unrelated note, why hasn't it remained in the repos? Its takes quite a long time to build. Let me know i