Focal Point
[SOLVED] Date to miliseconds conevrsion

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

April 14, 2011, 02:28 PM
LMP
[SOLVED] Date to miliseconds conevrsion
Hi , I have a requirement where te date format yyyy-mm-dd should be converted to milliseconds. I tried using htime but it is giving me wrong result. Please let me know the function tat wud solve my issue.

This message has been edited. Last edited by: Kerry,
April 14, 2011, 04:13 PM
Francis Mariani
How does one convert a particular date to milliseconds? Milliseconds is a duration.

I can tell you how many milliseconds are in one day (1 day = 24 hours = 86,400,000 milliseconds), I can tell you how many milliseconds there are in 24 June, 2011, the same number as in 17 February, 1993 - every day has the same number of milliseconds.

I can tell you how many milliseconds there are between 5 August 2003 and 14 April 2011 - is that what you're looking for?


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
April 14, 2011, 04:21 PM
Prarie
Well this hasn't happened in forever. Welcome LMP - wonder why you did not have to put what version you are using. Thought that was a requirement when registering......


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Sorry if my question was wrong.

I am doing a Java rewrite to Web focus.

In java the milliseconds of a date is retrieved using Date.getTime() function. The input to this function is a date of format yyyy-mm-dd.
I am expecting something similar in webfocus.

By the way i am using WF version 7.6.9

Thanks,
LMP


7.6.9, Windows
Excel and HTML
Give me an example of a result of the Date.getTime() 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
http://download.oracle.com/jav.../java/util/Date.html

getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.


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
the input date given is 2011-04-13

and the o/p got was 1302494520000.

Thanks,
LMP


7.6.9, Windows
Excel and HTML
Try something like this:

-* File datedif2.fex

-SET &ECHO=ALL;

DEFINE FILE CENTORD
HDTTM0/HYYMDs = HINPUT(14,'19700101000000', 8, 'HYYMDs');
HDTTM1/HYYMDs = HDTTM(ORDER_DATE, 8, 'HYYMDs');
HDIFF_MS/D15  = HDIFF(HDTTM1, HDTTM0, 'millisecond', 'D15');
END

TABLE FILE CENTORD
PRINT
HDTTM0
HDTTM1
HDIFF_MS
END


You may have to adjust 1970/01/01 00:00:00 by four hours because Java is based on GMT - just compare a date to the results in your Java program.


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
-* File datedif2.fex

-SET &ECHO=ALL;

DEFINE FILE CENTORD
HDTTM0/HYYMDs = HINPUT(14,'19700102200000', 8, 'HYYMDs');
HDTTM1/HYYMDs = HINPUT(14,'20110413000000', 8, 'HYYMDs');
-*HDTTM1/HYYMDs = HDTTM(ORDER_DATE, 8, 'HYYMDs');
HDIFF_MS/D15  = HDIFF(HDTTM1, HDTTM0, 'millisecond', 'D15');
END

TABLE FILE CENTORD
PRINT
HDTTM0
HDTTM1
HDIFF_MS
BY ORDER_DATE
WHERE RECORDLIMIT EQ 1
END


For some reason, the base date needs to be near 1970/01/02/20:00:00 to get close to your value of 1,302,494,520,000. My code gives 1,302,494,400,000. So the base date needs to be tweaked by some minutes...


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
Hi Francis,

Thanks a lot. Tat worked. Now i want to convert milliseconds obtained back to a Timestamp .ie date and time.

I am completely new to WF. Hence the struggle. Searched the forum.. but cudnt find one.

Please let me know how to convert the ms to date-time.


7.6.9, Windows
Excel and HTML