How to convert Epoch time to Datetime (YYYYMMDDHH24MMSS)

Hi,
In our Oracle db, Datetime is stored as Epoch time (seconds since january 1st 1970). To get a readable date, I have converted those fields as followed:
TO_CHAR(TO_DATE('19700101000000', 'YYYYMMDDHH24MISS')+((DATE_FIELDS-18000) /(60*60*24)),'YYYYMMDDHH24MISS')
Result ex: 20100830135422
The problem is that the resulting fields are in VARCHAR2 instead of DATE so it causes issues in SAP BW reporting development. BW developpers can manage something to make it eventually work but I would like to correct this at the source if it is possible.
I have already tried to add another "TO_DATE" function at the beginning of the previous expression but I get a date in "DD-MMM-YY" format as a result even if I have forced another date format.
Any idea on how I could solve this?
Thanks a lot
Pascale

Ok, there is clearly a disconnect here.
Oracle stores dates in a DATE datatype. This means that, internally, it will store enough information for a 4 digit year, a month, date, hour in 24 hour time, minute, and second. All that information is stored in the DATE datatype inside the database, but, it's stored in an internal format, that has nothing to do with what it will look like when you print it. When you want to retrieve it, Oracle must have a date format string, so that it knows how to display that information. If you do not provide a date format string via the TO_CHAR() function, Oracle has a parameter called NLS_DATE_FORMAT that provides the default format to use. If you have not set the NLS_DATE_FORMAT, it defaults to DD-MON-YY.
So, having said all that, what are you actually trying to do?
You started with this expression:
TO_CHAR(TO_DATE('19700101000000', 'YYYYMMDDHH24MISS')+((DATE_FIELDS-18000) /(60*60*24)),'YYYYMMDDHH24MISS')How is that expression used? In a SELECT statement? Then you probably want it the way it's written above. In an INSERT statement? If so, then if the datatype of the column you're inserting into is DATE, then you probably need to eliminate that outer TO_CHAR conversion, so that the expression returns a date that can be inserted into DATE column.
Tell us more about what you want to do, and perhaps we can offer further help.
-Mark

Similar Messages

  • How to convert epoch time to datetime in sql*loader Oracle

    Hello,
    I wan't to question how to convert epoch time to datetime in sql*loader Oracle. I try this script for convert epoch time to datetime in sql*loader, but error:
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    This is my loader:
    LOAD DATA INFILE 'C:\Documents and Settings\Administrator\My Documents\XL_EXTRACT_211\load.csv'
    into table TEMP_TEST_LANGY append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    DATADATA CHAR "TO_DATE('01-JAN-1970','DD-MON-YYYY')+:datadata/86400"
    This is my csv file:
    79314313.7066667
    79314336.2933333
    79314214.3466667
    This is my table:
    CREATE TABLE TEMP_TEST_LANGY
    DATADATA DATE
    Thanks
    Edited by: xoops on Sep 21, 2011 8:56 AM
    Edited by: xoops on Sep 21, 2011 8:58 AM

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • How to convert epoch time stamp to timestamp.

    Hi,
    I need a help regarding how to convert the epoch Time stamp, to oracle date and time format.
    for example,
    for epoch time stamp:1204104116656
    the time stamp should be :2008-02-13 12:43:00.351
    Please help me on the same

    SQL> select timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second') from dual;
    TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 09.21.56.656000000 AM
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('EST') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 08.21.56.656000000 AM -05:00
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('PST') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 06.21.56.656000000 AM -07:00
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('Europe/Berlin') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 03.21.56.656000000 PM +02:00
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('Canada/Mountain') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 07.21.56.656000000 AM -06:00SY.

  • How to convert epoch time to EST/EDT

    10g sql

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • Converting EPOCH time stamp to time stamp in Oracle

    Hi,
    I need a help regarding how to convert the epoch Time stamp, to oracle date and time format.
    for example,
    for epoch time stamp:1204104116656
    the time stamp should be :2008-02-13 12:43:00.351
    Thanks in Advance
    Basil Abraham

    Are you sure you've got the right timestamp? Assuming this is a standard unix epoch time stamp with the epoch date starting at 1970-01-01 UTC the interval between 1970-01-01 UTC and 2008-02-13 is 13922 days, but your epoch timestamp divided by the number of miliseconds in a day 1204104116656/(1000*60*60*24) comes out to 13936.390... days a difference of 14 days 9 hours 21 minutes 56 seconds and 656 miliseconds.
    Anyway to convert you need to convert your epoch date into an interval and add it to the starting epoch date (as a timestamp):
    select to_timestamp_tz('1970-01-01 utc', 'yyyy-mm-dd tzr')+
           numtodsinterval(1204104116656/1000,'second') dstamp
    from dual;Message was edited by:
    Sentinel

  • How to Convert a 'Time Stamp' field to Date......?

    Hello Gurus:
    I am using a Generic Extractor to pull some stats data.  One of the field is a Time Stamp field, which tells me the date and time of Transaction run.  I only need "Date".  I tried mapping the stamp field to Date info-object hoping for a automatic determination of the Date.... (like the Week, Month happens).   Well, I was wrong! 
    I only need the Date part.  How can I do this in BI?  is teher a specific SAP info-object for this that could be used..?  If not, what would be the routine.  The Date field that comes in is a SAP format... "u201C20,070,505.0000000u201D meaning the Transaction was run
    on 05/05/2007.  How can I get this convertion in BI transaformation??  is there a special Routine...?
    Also, we are trying to use "Time Stamp" based DELTA from a generic extraction.  The field used is a System date with time stamp.  Value looks like u201C20100,505,170,113.2918470u201D, u201C20100,505,170,113.4748820u201D  Every record pulled has a different value... probably giving me the time at which the record was created or generated.  Now, with DELTA specifid on this type of field, what will be the 'Current Status" value in Delta queue?  Is it based on the last record created and will that be the highest value?  For next Delta extraction, does it compare the extraction time stamp to this value and bring in those records that are greater than the 'Current Status" value?  I guess with that we can have as many deltas as we want..... right??  is there any particular setting I should be doing or worried/ careful about setting etc....?
    Thanks for the response in advance....
    Best..... SMaa

    Thanks Akshay,
    Your suggestion worked right away and was probably the easiest of all.  I tried the Function Module that Pravender suggested,
    but it did not return me the date back.... may be because it does not need the Micro Seconds in it....?  Routine as suggested by
    Satyam might work too, but did not go there....! 
    Thanks to all of you.
    Best..... SMaa

  • Converting epoch time to a date

    Anyone know of a function to do this. I cant find any in the api and my searches bring up nothing.

    You can create your class that extends GregorianCalendar.Then you can access the protected class in super class. Following codes are what I write to handle this problem. Hope it help.
    import java.util.*;
    public class Test10{
         public Test10(){
              init();
         public void init(){
              MyCalendar calendar1 = new MyCalendar();
              calendar1.set(2002, 07, 12);
              System.out.println("time in epoch: " + calendar1.getTimeInMillis());
         public static void main(String[] str)
              new Test10();
         private class MyCalendar extends GregorianCalendar
              public MyCalendar(){
                   super();
              public long getTimeInMillis()
                   return super.getTimeInMillis();

  • How to convert date-time according to the Time Zone the client

    Urgent! Help wanted!
    I extract a date-time field (which is GMT time) from the central database but I need to convert it accordding to the TimeZone of the user and also the so-called winter time and summer time in the local. Any one has any good solution?
    Thanks.

    Use a Calendar, Timezone and Locale objects like this,
    TimeZone tz = TimeZone.getTimeZone("Germany/Berlin");
    Calendar cal = Calendar.getInstance(tz, Locale.GERMAN);
    long date = 0; // assign your central database value to this variable
    cal.setTime(new Date(date));
    Now you can use the Calendar object 'cal' to retrieve the time according to the set locale and timezone.
    These objects provide tonnes of features for finding out timezones and day light savings times. So check out the APIs as well.
    I hope this helps you out.

  • How to convert an time interval into float ?

    Dear oracle Experts,
    I have a question concerning time conversion.
    I would like to convert an interval like e.g.
    tsDuration INTERVAL DAY (9) TO SECOND;
    into a float which describes the interval as a fraction of a day where
    the pre decimal position is the number of days and the post decimal
    position the fraction of a day in a decimal syntax of the day.
    Are there conversion function available in Oracle 10g with which I
    could perform that task ?
    If there isn't a conversion function for that.what's the best way to do it ?
    Best regards,
    Daniel

    Hi Srini
    1. Copy/Paste Webdynpro components in the new project as was suggested before
    2. Or create new project, copy _comp folder from old project to the new one. But, do not forget to update .dcdef & .project files manually after this. You have to set the correct project name in .dcdef and set the correct local project path in .project.
    BR, Sergei

  • How to convert GMT time into IST on weblogic server

    Hello,
    i am using Weblogic server interconnected with webcenter content, in my application i am uploading document, the uploaded time it is showing is in GMT , and on oracle webcenter content i am getting uploaded time in Indian Standard Time that is "+05:30" so in my application what i can do to change time from GMT to Indian Standard Time
    Regards
    Mayur Mitkari

    Hi Mayur,
    As I mentioned earlier also change the system time then your weblogic will start taking IST time zone.
    Regards,
    Kal

  • [Oracle 8i] How to convert a string (time stamp) into a date?

    I'm having difficulty figuring out how to convert a time stamp string into a date (or possibly a number).
    The time stamp is 20 positions, character (NOT NULL, CHAR(20))
    in the format: YYYYMMDDHHMMSSUUUUUU
    where Y = Year, M = Month, D = Day, M = Minutes, S = Seconds, and U = Microseconds
    The reason I want to convert this is so that I can compare one time stamp to another (i.e. I want to be able to find the MIN(timestamp), MAX(timestamp), and do inequality comparisons).
    Is this at all possible?
    Thanks in advance for help on this!

    Hi,
    As Damorgan said, if all you want to do is find which is the earliest or latest, then you can just compare the strings: they happen to be in a format where that works.
    If you need to do other things, such as compare them to today's date, or see the difference between two of your rows in days, then you have to convert them to DATEs. (There's no point in converting them to NUMBERs).
    A new data type, TIMESTAMP, which handles fractions of a second, was introduced in Oracle 9.
    Since you're using Oracle 8 (according to your subject line), you either have to
    (1) ignore the microseconds, or
    (2) use a separate NUMBER column for the microseconds.
    Either way, use TO_DATE to convert the first 14 characters to a DATE:
    TO_DATE ( SUBSTR (txt, 1, 14)
            , 'YYYYMMDDHH24MISS'
            )where txt is your CHAR column.
    To convert the microseconds to a number (between 0 and 999999):
    TO_NUMBER (SUBSTR (txt, 15))

  • Convert date time local Timezone  to GMT

    I need to get GMT time...
    How to convert local time to GMT ?
         public static long getGMTNow()
             Calendar local = new GregorianCalendar();
             local.set(Calendar.HOUR_OF_DAY, 0);              
             local.set(Calendar.MINUTE, 0);
             local.set(Calendar.SECOND, 0);
             System.out.println(local.getTime());
             System.out.println(local.getTimeInMillis());
             Calendar gmtC = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
             gmtC.setTimeInMillis(local.getTimeInMillis());
             System.out.println(gmtC.getTime());
             return gmtC.getTimeInMillis();
         }Result :
    Thu Feb 12 00:00:00 EST 2009
    1234414800034
    Thu Feb 12 00:00:00 EST 2009
    1234414800034

    Calendar gpsTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
             gpsTime.set(Calendar.HOUR_OF_DAY, 10);              
             gpsTime.set(Calendar.MINUTE, 0);
             gpsTime.set(Calendar.SECOND, 0);
             System.out.println("gpsTime: "+gpsTime.getTime());
             Calendar realtime= new GregorianCalendar();
             realtime.set(Calendar.HOUR_OF_DAY, 5);              
             realtime.set(Calendar.MINUTE, 0);
             realtime.set(Calendar.SECOND, 0);
             System.out.println("realtime: "+realtime.getTime());
             System.out.println("COMPARETO : "+ realtime.compareTo(gpsTime));
             long timediff = realtime.getTimeInMillis() - gpsTime.getTimeInMillis();
             System.out.println(timediff/1000 + " sec");RESULT :
    gpsTime: Mon Feb 16 05:00:00 EST 2009
    realtime: Mon Feb 16 05:00:00 EST 2009
    COMPARETO : 1
    0 secOk, I done my homework. getTime() will allways return local time so I need to set the GPS time to a GMT Calendar to get the right result.
    Funny thing, look at the compareTo result....

  • Convert Epoch date to Minutes

    How to convert epoch date to minutes in CR XI?
    Can anyone help?

    It's my understanding that Epoch is the number of seconds that have elapsed since 1/1/1970.
    So is you want to convert it to a date, the following formula should work.
    DateAdd("s", {TableName.EpochDate}, #1/1/1970#)
    If all you are wanting to do is convert seconds to minutes, then simply divide by 60
    {TableName.EpochDate} / 60
    HTH,
    Jason

  • Convert system time into User local time.

    Hi,
    How to convert System time into User Local time.
    Are there any FMs available.
    Regards,
    Kiran

    hi,
    There is just one simple funda behind the Date and time logic in SAP.
    -> It is absolutely useless to store Date and time directly in DB. Why ?
    Because 00:00 a.m in London could mean 05:30 in India !! So If I (in India) store a Date 1st Feb 2008 , 10:00 a.m .. This time for a person in London could be invalid.. because he is behind your time zone..
    So the solution is to store the date/times in Timestamps format. Taking the above example.. 1st Feb 2008, 10:00 a.m (in India) will be stored as 20080201043000.
    This time if seen in German Time zone will look as : 1st Feb 2008, 05:30 a.m.
    Simple right
    -> In India we store date as DD.MM.YYYY while in other countries they store it as MM.DD.YYYY.
    The separator could be . or - or / .
    The date format is user dependent. I might prefer to store it as DD.MM.YYYY and you might want to store it as MM-DD-YYYY.
    System does not bother what your format is. It always stores in YYYYMMDD (8 Char)
    On screens if you want to display Date then it must always be shown in that users format who is seeing it. How to get this done ?
    DATA : lv_date(10) type c.
    write sy-datum into lv_date.
    So in LV_DATE variable the date will be stores in the users format.
    Simple right
    There are function modules that do the same. But normally we should avoid use of FM to make code simpler, short and easy... no complications at all ..
    You can use system variables sy-datlo (Local Date for Current User) and sy-timlo ( Local Time of Current User ).
    You can also use GET TIME statement.
    reward if useful,
    preet

  • Convert Epoch Date Time to Date Time format

    I am trying to convert Epoch Date time in GMT to Human Readable Date time format in UTC. I used the one below but it returns just the date in GMT but how can get datetime in UTC ?
    select To_Char( To_Date( '01.01.1970 06:00:00','DD.MM.YYYY HH24:Mi:Ss') + STARTIME / 86400,'DD.MM.YYYY HH24:Mi:ss') FROM HQ_AVAIL_DATA_RLE;
    I refered a couple of forums and applied everything, but still I wouldn't get the timestamp.
    Please note that i'm looking for datetime stamp, not just the date.
    Thanks in advance!
    Edited by: 830754 on Jan 27, 2011 11:18 AM
    Edited by: 830754 on Jan 27, 2011 11:19 AM

    Works for me. I see date and time (submitted 1000 for STARTTIME):
    select To_Char( To_Date( '01.01.1970 06:00:00','DD.MM.YYYY HH24:Mi:Ss') + 1000 / 86400,'DD.MM.YYYY HH24:Mi:ss')
    from dual
    TO_CHAR(TO_DATE('01
    01.01.1970 06:16:40Or do you mean something else?

Maybe you are looking for

  • Error while creating a new connection in ODSM for OVD

    Hi all, I am getting the following error while creating a new connection in ODSM for OVD. Error log: [2012-07-10T14:50:30.005+05:30] [wls_ods1] [ERROR] [] [oracle.adfinternal.view.faces.config.rich.RegistrationConfigurator] [tid: [ACTIVE].ExecuteThre

  • Bug report: Safari 5 fails to handle 8192 bit RSA certificates

    Running Safari 5.1.7 on OS X 10.6.8 -- I haven't confirmed for the version of Safari running on 10.7 -- and trying to access a site over https that uses an 8192 bits large RSA cert causes Safari to bug out. It can't display the certificate details co

  • Can I select a rectangle in pdf document, identify the bounds, and then retrieve the text with vba?

    I am using MS Access 2010 VBA and acrobat X, and AcroExchg.  I can manipulate and search pdf documents without difficulty.  I would like to programmatically capture the text in a rectangle that I have drawn on the document with a mouse.  It appears t

  • Method to browse/edit  the user/group in SunOne DS  on client side

    I had installed a sunone directory server in a window 2003 server. I want to allow user/client to edit the group/user attribute, how can I do that? Exclude writing a java program to retrieve the information from the sun one directory server, are ther

  • Altering authorization objects

    Hi all,   I copied the existing role to a new role and need to do some modifications to authorization objects. I entered the new role in change mode but in authorizations tab, I only have 'display authorization data' mode. I can not get it to 'change