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]Calculating previous year date for an MDYY date.
Go
New
Search
Notify
Tools
Reply
  
[Solved]Calculating previous year date for an MDYY date.
 Login/Join
 
Platinum Member
posted
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,


WF8202M,Windows 7,8,10
HTM,PDF,EXCEL
 
Posts: 207 | Location: MI | Registered: September 13, 2017Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 1560 | Location: Customer Support | Registered: April 12, 2005Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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.


WF8202M,Windows 7,8,10
HTM,PDF,EXCEL
 
Posts: 207 | Location: MI | Registered: September 13, 2017Reply With QuoteReport This Post
Expert
posted Hide Post
  
-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 7.7.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1946 | Location: Parker, CO | Registered: January 31, 2006Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Thanks Tom,

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


WF8202M,Windows 7,8,10
HTM,PDF,EXCEL
 
Posts: 207 | Location: MI | Registered: September 13, 2017Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Solved]Calculating previous year date for an MDYY date.

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