Focal Point
[Solved]Convert UNIX Timestamp to DATE

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4137021096

May 10, 2018, 10:27 AM
WFDevConsultant
[Solved]Convert UNIX Timestamp to DATE
I am getting the date from BOTLOG2 table in the UNIX Timestamp format and would like to convert that to DATE.

Used DATECVT(UDATE,'MDYY','I8MDYY') but it gives 12/31/1900.

How can I convert the Unix Timestamp to a proper date?

This message has been edited. Last edited by: WFDevConsultant,


8.2.06
Windows, All Formats
May 10, 2018, 10:46 AM
Efrem
This is what works for me:

-SET &NOW = DT_CURRENT_DATETIME(MILLISECOND);
-SET &NOWZ = HGETZ(8,'HYYMDs');
-SET &ANOW = DT_FORMAT(&NOW,'HYYMDs');
-SET &ANOWZ = DT_FORMAT(&NOWZ,'HYYMDs');
-SET &OFFSET = DTDIFF(&NOWZ,&NOW,HOUR);
-*
DEFINE FILE wfcrest/GET_ITEMS
BASEDATE_HYYMDS/HYYMDS=HINPUT(19, '1970-01-01 00:00:00', 8, 'HYYMDS');
CREATEDON1_HYYMDS/HYYMDS=DTADD(HADD(BASEDATE_HYYMDS, 'SECONDS', CREATEDON1/1000 , 8, 'HYYMDS'),HOUR, &OFFSET*(-1));
END

You should be aware that with WebFOCUS 8203, there's a WebFOCUS Adapter which has examples and is able to integrate with the WebFOCUS Repository which includes ReportCaster.

Efrem
May 10, 2018, 10:58 AM
Francis Mariani
Since it's a time-stamp or date-time column, you need to use date-time functions.

Try:

COMPUTE TDATE2/YYMD = HDATE(RUN_TIMESTAMP, 'YYMD');



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 10, 2018, 11:04 AM
Efrem
Francis,
I Unix Timestamp is a numerical number representing number of seconds from January 1, 1970.


Efrem
May 10, 2018, 11:07 AM
WFDevConsultant
The Timestamp data will look like this 1525818530294.

Tried both Francis and Efrem suggestions but nothing worked.

Efrem's suggestion code
RDATE2/HYYMDS=HINPUT(19, LOGGED_STAMP, 8, 'HYYMDS');
RDATE1/MDYY=HDATE(RDATE2,'MDYY');

Francis suggestion code
RDATE1/MDYY=HDATE(LOGGED_STAMP,'MDYY');


8.2.06
Windows, All Formats
May 10, 2018, 11:08 AM
Francis Mariani
Thanks Efrem.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 10, 2018, 11:15 AM
Francis Mariani
So, is this considered "Zulu time"?

If so, then this may be helpful:

Zulu Time – How to Read the ReportCaster Schedule File

Or this?

[SOLVED] Timestamp to date conversion

There are other search results...

BOTLOG2 is in a database - so maybe the easiest way is to use a DBMS function...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 10, 2018, 04:26 PM
Edward Wolfgram
Try this:
DEFINE FILE CAR
UTIME/D13 WITH COUNTRY = 1525818530294 ;
NEWDT/HYYMDs = HADD(DT(JAN 1 1970),'ms',UTIME,8,'HYYMDs') ;
END
TABLE FILE CAR
PRINT UTIME NEWDT
IF RECORDLIMIT EQ 2
END
-RUN
-EXIT

PAGE     1
 
 
             UTIME  NEWDT                                                      
             -----  -----                                                      
 1,525,818,530,294  2018/05/08 22:28:50.294
 1,525,818,530,294  2018/05/08 22:28:50.294



Basically, add the input milliseconds to the base date of Jan 1 1970.


IBI Development
May 11, 2018, 11:26 AM
dhagen
quote:
Originally posted by Francis Mariani:
BOTLOG2 is in a database - so maybe the easiest way is to use a DBMS function...


This is what I usually do. This also helps with DST evaluations. Sample for PostgreSQL
 DB_EXPR(to_timestamp(left(ltrim(to_char(probe_dt_unix,'99999999999999999999999999'), ' '),10)::int) at time zone 'EST5EDT'); 

All the extra stuff was because of bad data.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
May 14, 2018, 09:36 AM
WFDevConsultant
Hi All,

First Thanks to everyone for their suggestions and the code. Edward's solution worked for us.

Once again, Thanks to all of you and happy to be part of this forum.

Thanks


8.2.06
Windows, All Formats