Hello to All,
I need to calculate a date. I am unsure how to ask the question so I will try to explain:
Today is Tuesday Jan 04, 2011, one year ago it was Tuesday Jan 05, 2010 and two years ago it was Tuesday Jan 06, 2009.
The reason I need this function, if you want to call it that, is we run 2 and 3 year comparinson reports. I run the same report 3 times for the 3 different days. I would like to run this report once and be done with it. Does anyone have a function that would solve my problem? Also it would have to account for leap year.
If you have any questions please let me know.
DavidThis message has been edited. Last edited by: Kerry,
Today is Tuesday, January 4, 2011.
One year ago it was Monday, January 4, 2010.
This is a program that calculates the dates. It uses the DATEADD function. Since the program uses Dialogue Manager variables in the function, the variable is converted to a date field using the DATECVT function, then to be able to use the results of the DATEADD function, DATECVT is used once again to convert the result back to an integer. DATEADD most likely takes care of leap years.
-* File dates4.fex -SET &INPUT_DATE = '20110104'; -*-- DETERMINE PRIOR DATES --- -SET &INPUT_DATE1 = DATECVT( DATEADD(DATECVT(&INPUT_DATE,'I8YYMD','YYMD'),'Y', -1), 'YYMD','I8YYMD'); -SET &INPUT_DATE2 = DATECVT( DATEADD(DATECVT(&INPUT_DATE,'I8YYMD','YYMD'),'Y', -2), 'YYMD','I8YYMD'); -SET &INPUT_DATE3 = DATECVT( DATEADD(DATECVT(&INPUT_DATE,'I8YYMD','YYMD'),'Y', -3), 'YYMD','I8YYMD'); -*-- DISPLAY DATES --- -TYPE Input date: &INPUT_DATE -TYPE Input date 1 year ago: &INPUT_DATE1 -TYPE Input date 2 years ago: &INPUT_DATE2 -TYPE Input date 3 years ago: &INPUT_DATE3
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
If you want to stay with the same day of week and week number, this may work for you. Change WEEKFIRST for your standard.
-SET &INPUT_DATE = '2011/01/04'; SET WEEKFIRST = ISO1 -*SET WEEKFIRST = ISO2 DEFINE FUNCTION MOVE_YR(date/A10,period/I4) Act_Date/HYYMD = HINPUT(10,date,8,'HYYMD'); Week/I4 = -(period * 52); New_Date/HYYMD = HADD(Act_Date,'wk',Week,8,'HYYMD'); Week_Date/HYYMD = HADD(New_Date,'wk',HPART(Act_Date,'wk','I2') - HPART(New_Date,'wk','I2'),8,'HYYMD'); MOVE_YR/A10 = HCNVRT(Week_Date,'(HYYMD)',10,'A10'); END -RUN -TYPE Input date initial value: &INPUT_DATE -SET &N_YR1 = MOVE_YR(&INPUT_DATE,1); -SET &N_YR2 = MOVE_YR(&INPUT_DATE,2); -SET &N_YR3 = MOVE_YR(&INPUT_DATE,3); -SET &N_YR4 = MOVE_YR(&INPUT_DATE,4); -TYPE Input date: &INPUT_DATE changed to: &N_YR1 -TYPE Input date: &INPUT_DATE changed to: &N_YR2 -TYPE Input date: &INPUT_DATE changed to: &N_YR3 -TYPE Input date: &INPUT_DATE changed to: &N_YR4
6-Jan. Had to tidy up as this was not the best example of using date functions...This message has been edited. Last edited by: Alan B,
|Powered by Social Strata|