Convert date/time to Unix epoch

I have thousands of date time stamps I would like to convert to Unix epoch ten-digit strings. That is, take some thing like:
Dec 9, 2005 10:24 AM
and convert to
1234567890 (only in the correct unix epoch time)
What formula can I use? I've found that this "=DATE(1970,1,1)+P2/86400" can convert a 10 string epoch time down to just a date correctly, but without time. But I need to go in the opposite direction, with the time included.
Using Numbers 09 ver 2.0.5 (368)

CP,
An up-to-date Unix Time would be provided by:
=DUR2SECONDS((NOW()-"1/1/1970"))
A somewhat more robust form would be:
=DUR2SECONDS(NOW()-DATE(1970,1,1))
If the time to be converted is in Cell P2, the expression would be:
=DUR2SECONDS(P2-DATE(1970,1,1))
Jerry

Similar Messages

  • How to return start and end time in Unix epoch format

    Hi: I have a integer field (utime) in a table that stores the UNIX epoch time for a record. Every sunday around 2:00AM, I am running a query which should return records from last week. I want my condition to have the following in it's where
    WHERE utime between
    (convert sysdate-7 12:00AM to Unix time)
    AND
    (convert yesterday 11:59PM to Unix time)
    Can someone help me create this convert?
    Thanks
    Ray

    Yes, you seem to have worked out the logic of the expression correctly. Though, in your earlier post you had said that you want records within the range:
    WHERE utime between
    (convert sysdate-7 12:00AM to Unix time)
    AND
    (convert yesterday 11:59PM to Unix time)But now you are adding 14400 (4hrs) and deducting 72000 (20hrs) in your expression
    SELECT * from TABLE
    WHERE utime between
    ((TRUNC(SYSDATE,'DD')-TO_DATE('01/01/1970','MM/DD/YYYY'))*(24*60*60))+14400 AND
    ((TRUNC(SYSDATE-6,'DD')-TO_DATE('01/01/1970','MM/DD/YYYY'))*(24*60*60))-72000;Which makes your new condition to be:
    WHERE utime between
    (convert sysdate 04:00AM to Unix time)
    AND
    (convert sysdate-7 04:00AM to Unix time)
    Are you sure you need records from 4am-to-4am and not midnight-to-midnight? And yes, with BETWEEN condition you need to use expression '<low-value> AND <high-value>' and not '<high-value> AND <low-value>'!
    Besides this,
    1. You might want to use bind variables rather than hard-coded expressions in your statement. Infact your expression uses SYSDATE, so Oracle would need to get current SYSDATE for each row to evaluate the expression. Which is going to have its impact on performance. As your start-time and end-time values are not dependent on table data maybe you could have a code like this (assuming it is PLSQL code):
    start_time constant number := (convert sysdate-7 12:00AM to Unix time);
    end_time constant number := (convert yesterday 11:59PM to Unix time);
    <DML or Cursor with condition>
    WHERE utime between start_time and end_time;
    2. You said that your table already has values in unix-epoch-time in column 'utime'. How are these values inserted in the first place? Is there a function in your application that converts any given time to unix-epoch-time? Is yes, then use that in your code.
    3. If such a function does not exists, than rather than using hard-coded expressions it might be a good idea to create new functions for converting to and from unix-epoch-time and to get current unix-epoch-time from server.
    Using a function in the above case:
    start_time constant number := f_convert_to_unix_time( trunc( sysdate-7 ));
    end_time constant number := f_convert_to_unix_time( trunc( sysdate )) - 1;
    <DML or Cursor with condition>
    WHERE utime between start_time and end_time;
    And lastly, some of us might not know about Unix time, so here is a useful link http://en.wikipedia.org/wiki/Unix_time

  • How convert date/time from xml in xdp(Designer)?

    Hi, i want to convert date/time format from xml in Designer, date/time value in xml is NOT in common format YYYY-MM-DD (if is in a common format i can do this with pattern)
    I have a "DateTime" Field in Xdp can get from Xml date and time:
    In XML <DateTime>DD-MM-YYYY</DateTime> i want to convert in XDP in DateTime Field in "DD-April-YYYY"
    Can i do this?

    You can do this way..
    Bind the date field to your XML tag.
    Set the display pattern for the date field.
    In the initialize event of the date field place the following code.
    Set JavaScript as language.
    var dtStr = this.rawValue;
    var pos1=dtStr.indexOf("-");
    var pos2=dtStr.indexOf("-",pos1+1);
    var strMonth=dtStr.substring(0,pos1);
    var strDay=dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    //Assign the formatted value to the Date field.
    this.rawValue = strYear + "-" + strMonth + "-" + strDay;
    Thanks
    Srini

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • Update date/time in UNIX timestamp format

    The datetime in my Oracle DB is being stored in UNIX Date Time format.
    Is there a way I can set the date/time using an UPDATE statement in such a case.
    for eg:
    select id, creation_date, expiration_date from skel;
    id creation_date expiration_date
    400019 1213726470     
    400020 1213733052     
    400005 1210867973     
    400018 1213723608     
    I am looking to set the expiration date as creation_date + 1 year.
    Could you please advise?

    I am looking to update the value in the field. The values will still be in UNIX date/time format.Yes, but still: instead of continuing converting to Oracle dates and Unix dates, why not just store dates the way the datebase can deal with it the best?
    You're probably storing your UNIX date/time formatted dates in the database as NUMBERS.
    That is a great loss of lots of built-in date functionality Oracle Database provides.
    If you insist on staying on that road, then explore my previous links, you will find your answer:
    Convert epoch number to date, do arithmatic and convert the result back to epoch number.
    That is overkill.
    It won't work/scale/perform/whatever in the end. It is a bad approach.
    So, please reconsider this:
    Why are you storing dates as numbers?
    Convert those numbers to dates once, and be done with it for ever after and benefit from all the builtin date-functionality Oracle database comes with, or convince us that you really have a valid reason to store dates in UNIX date/time format into an Oracle Database.
    and my last date was...uuhhmm... never mind ;)

  • Convert date/time to a value in second

    Hello,
    I want to convert a basic date time variable into a numeric one corresponding to the time (in second) passed since January,1,1970 in order to put it in a SQL statment as a criteria.
    Is someone able to help me ?
    Regards

    If you have an java.util.Date object you can call getTime() method on it. It will return milliseconds. Just divide it on 1000. Here is example code:
    java.util.Date date = new java.util.GregorianCalendar(2001, 7, 6).getTime();
    long seconds = date.getTime() / 1000;
    //Your code
    Best regards, Alex.

  • 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.

  • 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

  • Time from UNIX epoch

    I have the number of micro seconds from the UNIX epoch time 00:00:00 UTC 1
    Jan 1970. (1092727073895638 usec)
    I want to know the time in CST.
    I have been trying to work with the Calendar class and GregorianCalendar.
    But I am not quite getting it. Could someone give me an idea of what I need
    to do.
    Thanks
    Ox

    You need to set a TimeZone in your Calendar or GregorianCalendar. Then format using SimpleDateFormat. Post the code that you tried, and explain what isn't coming out correctly.

  • 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 date/time to HEX command and write to a bin file

    Hello,
    I have to do the following thing. I have the date/time string, let's say 08:45:23, 12.08.09, where the hour, the minutes, the seconds, the day, the month and the year represent hex number or in other words I have the following command:
    Byte 0 - Byte 5
    0x08; 0x45; 0x23; 0x12; 0x08; 0x09;
    Now I want to write this command in a binary file in order to send thefile later throught serial RS232 connection.
    Now, I am not sure whether I write the command in the binary file in the correct format. What I simply do is to write it as a string
    ("084523120809"). Is this the correct way. I guess no, because when transmitted it does not work as expected.
    How can I write this string as a HEX command in the binary file?
    Thanks for the replies in advance
    IG
    Message Edited by igurov on 08-12-2009 01:51 AM
    Attachments:
    1(2).JPG ‏39 KB

    Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").
    Attachments:
    time hex.vi ‏12 KB

  • Convert Date Time field to Date & Time

    Post Author: Smita
    CA Forum: Crystal Reports
    I am new to Crystal XI  . I need to convert DateTime ("2007/04/04/04 09:49:05:00") format to Date and Time and then group a months data first by date and then by Time ( per Hour ).
    If someone can help ?
    Thanks

    Post Author: newcruser
    CA Forum: Crystal Reports
    Thanks
    This is easy...second group based on the second formula 'for each hour'.
    How you group by 15 minutes?.
    i want to group by every 15 minutes starting from 9 AM to 5 PM.
    First i need to create a time range and then use that time range to group?.  Or any other simple and best way to solve this?. Please help
    How to create time range from 9 AM to 5 PM?

  • Internationalization  issue : convert date/time to GMT/UTC

    We have our webservices running in websphere /oracle.There is this requirement to internationalize the application ...like
    a) language .....
    d)Internatiolization of time :
    For this requirment I am planning to do the following.Service request with date will be converted to GMT before it is stored in database and the response back will be converted from GMT back to the time zone of the requester and have the application server/database server configured to UTC time.Is this a good strategy or is there a better one.
    Thanks
    m

    Manjit wrote:
    Sabre,to confirm again...you are suggesting that there is even no need to change the oracle Date field from Date type to Timestamp.The only thing I really have to do is for display purpose convert/format the response date to the zone the request is coming from.Please let me know if I missed anything.The above statement is indefinite.
    Are you starting with a java.util.Date or perhaps a java.sql.Timestamp?
    Then you do NOT convert them. You display them. You use SimpleDateFormat for that. You do not concern yourself at all with timezones exception in terms of creating a SimpleDateFormat. And that is ONLY an issue if you are creating the string (display value) on a server. If you are doing that you will need the client to provide you with a timezone. There is no magic way to get that from the client. If a client app is doing the display the the client is running in a client VM and that VM will already have a display format that might be suitable.
    Conversely if you are receiving a timestamp value as a text value (say read it from a file) then you must convert that into a java.util.Date. You do that via SimpleDateFormat. The specifics of how you do that depends on the form of the text value.

  • Convert date/time to GMT format

    Hi,
    I want to convert my current system date to GMT format. the class java.util.Time/Calender have methods which help u to convert from GMT to local time.
    is there a method to convert from current System Date to GMT.
    tx in advance

    i found the answer to my earlier question from the postings. Now i need help with the format og the Date in GMT.
    i used the following code to get the GMT based on the system time
    Calendar here = Calendar.getInstance();
    int gmtoffset = here.get(Calendar.DST_OFFSET)
    + here.get(Calendar.ZONE_OFFSET);
    //to convert to GMT time
    Date GMTDate = new Date(System.currentTimeMillis() - gmtoffset);
    the result of exceuting the following code is
    GMT Date is Mon Aug 20 18:39:19 EDT 2001
    but i need the GMT time in this format
    20010820-18:39:40
    tx
    Namrata

  • Convert date time to file date time

    Hi,
    I have standard delphi function which conver datetime to filedatetime here is the description
    function DateTimeToFileDate(DateTime: TDateTime): Integer;
    Description
    Use DateTimeToFileDate to convert a TDateTime value, which is the representation of date-and-time values used by the VCL, to a DOS date-and-time value.
    For example, use DateTimeToFileDate to convert a TDateTime value to a
    format that can be used as the Age parameter of FileSetDate. You may
    also need to use DateTimeToFileDate to convert a TDateTime so that it
    is compatible with the Time field of the TSearchRec record used by the FindFirst
    and FindNext functions.
    Lo returns the low-order Byte of the argument X as an unsigned value. X is an expression of type Integer.
    Use Hi to obtain the high-order byte of an expression of type Word or Integer.
    Note:     Hi treats Integer as a 16-bit value, even if it is 32-bit.
    This is the delphi code that convert the date
    year=2003
    month=5
    day=28
    sec=57
    min=45
    hr=13
    msec=107
    LongRec(Result).Lo := (Sec shr 1) or (Min shl 5) or (Hour shl 11);
    LongRec(Result).Hi := Day or (Month shl 5) or ((Year - 1980) shl 9);
    output Result is --> 784100796
    Any help will be highly appreciated.
    Thanks.

    You use the java.util.GregorianCalendar to extract month, day, etc from a date.
    Then you use the shift operator ('<<') to construct the number.

Maybe you are looking for