Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Solved]Convert UNIX Timestamp to DATE
Go
New
Search
Notify
Tools
Reply
  
[Solved]Convert UNIX Timestamp to DATE
 Login/Join
 
Platinum Member
posted
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,


7.7.03/8.0.0.7
Windows, All Formats
 
Posts: 160 | Registered: December 27, 2013Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 217 | Location: New York | Registered: July 27, 2004Reply With QuoteReport This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Francis,
I Unix Timestamp is a numerical number representing number of seconds from January 1, 1970.


Efrem
 
Posts: 217 | Location: New York | Registered: July 27, 2004Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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');


7.7.03/8.0.0.7
Windows, All Formats
 
Posts: 160 | Registered: December 27, 2013Reply With QuoteReport This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Reply With QuoteReport This Post
Gold member
posted Hide Post
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
 
Posts: 57 | Registered: November 15, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 1100 | Location: Toronto, Ontario | Registered: May 26, 2004Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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


7.7.03/8.0.0.7
Windows, All Formats
 
Posts: 160 | Registered: December 27, 2013Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Solved]Convert UNIX Timestamp to DATE

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.