Search code examples
javaoraclesastimestamp

How to convert Oracle/Java datetime in long type


I have timestamps from Oracle stored in a CSV file as data type long. This timestamp is generated using the Java function getTime(), see https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html

Timestamp looks like this, for example: 1723207241234. In the Oracle documentation I found that it is milliseconds since January 1, 1970, 00:00:00 GMT.

So, I need to parse timestamp generated using Java function in Oracle (get date and time from timestamp) and store these values ​​in SAS tables. Is there any way to do this?


Solution

  • SAS stores its datetimes since seconds from Jan 1st, 1960 00:00:00 GMT. To convert this to a SAS datetime, you must add 10 years to the Unix datetime value in seconds. '01JAN1970:00:00'dt in SAS converts to 10 years in seconds.

    data want;
        time = 1723207241234/1000 + '01JAN1970:00:00'dt;
        format time datetime20.;
    run;
    
    time
    09AUG2024:12:40:41