Focal Point
[Solved]Calculating previous year date for an MDYY date.

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

October 11, 2018, 11:39 AM
srajeevan
[Solved]Calculating previous year date for an MDYY date.
Hi All,

I am trying to calculate previous year date for below dates in MDYY format.

 
-DEFAULT &START_DATE   = '04/02/2018' ;
-DEFAULT &END_DATE     = '04/05/2018' ; 


DATECVT won't work directly on these dates as it is in MDYY ,so tried to convert to YYMD.
No ready to use functions are available as far as i undersatnd. So i spitted the MDYY and then joined back in YYMD format as below.

  
-SET &DATE_M = EDIT(&START_DATE,'99');
-SET &DATE_D = EDIT(&START_DATE,'$$$99');
-SET &DATE_YY = EDIT(&START_DATE,'$$$$$$9999');
-SET &START_DATE_YYMD = &DATE_YY||&DATE_M||&DATE_D;


My belief is that &START_DATE_YYMD is of A8YYMD format now.

SO tried to apply DATECVT on that to convert to YYMD.But it is not working.
Eventually i have to calculate previous year for the dates.To use DATEADD function i need to convert the dates to YYMD.
Am i doing something wrong? Code below.


  
-SET &ECHO='ALL';

-DEFAULT &START_DATE   = '04/02/2018' ;
-DEFAULT &END_DATE     = '04/05/2018' ;

-DEFAULT &PRIOR_START_DATE   = '01/02/2017' ;
-DEFAULT &PRIOR_END_DATE     = '02/01/2017' ;

-SET &DATE_M = EDIT(&START_DATE,'99');
-SET &DATE_D = EDIT(&START_DATE,'$$$99');
-SET &DATE_YY = EDIT(&START_DATE,'$$$$$$9999');
-SET &START_DATE_YYMD = &DATE_YY||&DATE_M||&DATE_D;

-SET &PRIOR_START_DATE = DATECVT(&START_DATE_YYMD,'A8YYMD','YYMD');
-*-SET &PRIOR_START_DATE = DATEADD(&START_DATE_YYMD,'Y',-1);
TYPE &DATE_M
TYPE &DATE_D
TYPE &DATE_YY
TYPE &START_DATE_YYMD
TYPE &START_DATE_MDYY
TYPE &PRIOR_START_DATE



Any suggestions ?

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


WF8206,Windows 7,8,10
HTM,PDF,EXCEL
October 11, 2018, 11:47 AM
FP Mod Chuck
srajeevan

Try this.

-SET &PYEAR_DATE=AYMD(&YYMD,-365,'I8YYMD');
-SET &START_DATE= EDIT(&PYEAR_DATE,'$$$$99') | '/' | EDIT(&PYEAR_DATE,'$$$$$$99') | '/' | EDIT(&PYEAR_DATE,'9999');


Thank you for using Focal Point!

Chuck Wolff - Focal Point Moderator
WebFOCUS 7x and 8x, Windows, Linux All output Formats
October 11, 2018, 11:55 AM
srajeevan
Hi,

Thanks for the reply.
You are calculating previous year from a YYMD date,but for my requirement,the date is in MDYY format.

If the date is YYMD format i can directly use DATECVT function or the AYMD function you provided.
Date being in MDYY is creating trouble for me as converting MDYY to YYMD is not happening properly when i split the date to components.


WF8206,Windows 7,8,10
HTM,PDF,EXCEL
October 11, 2018, 11:55 AM
Tom Flynn
  
-DEFAULT &SELECT_DATE = '04/02/2018';
-SET &SELECTED_CURR_YR = EDIT(&SELECT_DATE,'$$$$$$9999');
-SET &SELECTED_PREV_YR = &SELECTED_CURR_YR - 1;
-SET &PREVIOUS_DATE = EDIT(&SELECT_DATE,'999999') || &SELECTED_PREV_YR;
-TYPE &SELECTED_CURR_YR
-TYPE &SELECTED_PREV_YR
-TYPE &PREVIOUS_DATE
-EXIT



Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
October 11, 2018, 11:59 AM
srajeevan
Thanks Tom,

That was an easy fix.
I was thinking too much,i guess.


WF8206,Windows 7,8,10
HTM,PDF,EXCEL