Focal Point
[CLOSED] Date question

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

January 04, 2011, 03:44 PM
DETice
[CLOSED] Date question
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.

Thanks
David

This message has been edited. Last edited by: Kerry,
January 04, 2011, 04:28 PM
Francis Mariani
Today is Tuesday, January 4, 2011.

One year ago it was Monday, January 4, 2010.

etc.

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



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
January 05, 2011, 07:55 AM
Alan B
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,


Alan.
WF 7.705/8.007
January 05, 2011, 10:02 AM
Doug
That's a nice use of DEFINE FUNCTION.




   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Current: WebFOCUS Administrator at FIS Worldpay | 8204, 8206