[Solved] Find First Sunday or Last Saturday of a month.
I am trying to calcuate the beginning and ending dates of my fiscal year for the next 60 years. This has presented certain challenges for me because our Fiscal Year year begins with the first week in the accounting month of February and ends after the last week in the next January's accounting month.
I have seen the formulas for getting the begining and ending of the month but I was wondering if there was an easy way to get the last saturday of January and then the first Sunday in February.
WebFOCUS 7.6 Windows Output: Excel, HTML and PDFThis message has been edited. Last edited by: peechy23,
WebFOCUS 8.09 Windows, All Outputs
March 26, 2012, 03:13 PM
j.gross
My understanding is that your fiscal years end on the last Saturday of calendar January. The following code calculates January 31, determines its day of week, and adjusts the date accordingly to the last Saturday.
DEFINE FILE CAR
SEQ/I4 WITH MODEL = SEQ+1;
YEAR/YY = 2000 + SEQ;
JAN01/WMDYY=YEAR;
JAN31/WMDYY=JAN01+30;
WD31/WTR=JAN31;
NWD31/I1=WD31;
NADJ/I1=IMOD(NWD31+1,7,'I1');
FYEND/WMDYY=JAN31-NADJ;
END
-RUN
TABLEF FILE CAR
PRINT
YEAR
JAN31
NWD31
NADJ
FYEND
END
Thank you very much for the quick response on both of these. They are correct for most but I run into problem every now and then when we have a 53 week year instead of 52. I am not sure what the pattern is for that. Below is a list of what I crurrently have available out to 2018 for starting and ending dates.
Any thoughts on how I can incorporate this into a formula?
WebFocus 7.6 Windows Outputs: Excel, HTML and PDF
WebFOCUS 8.09 Windows, All Outputs
March 26, 2012, 07:25 PM
Crymsyn
Looking at your latest post it seems to follow fairly closely to be the 5th week in a year.
I mainly edited j.gross's example to change from getting the FYEND to getting the start based off of the 5th week instead of the end of January.
DEFINE FILE CAR
SEQ/I4 WITH MODEL = SEQ+1;
YEAR_STA/YY = 2000 + SEQ;
JAN01_STA/WMDYY=YEAR_STA;
JAN31_STA/WMDYY=JAN01_STA+34;
WD31_STA/WTR=JAN31_STA;
-* NWD31_STA/I1=WD31_STA;
NADJ_STA/I1=IMOD(WD31_STA,7,'I1');
FYSTA/WMDYY=JAN31_STA-NADJ_STA;
YEAR_END/YY = 2001 + SEQ;
JAN01_END/WMDYY=YEAR_END;
JAN31_END/WMDYY=JAN01_END+33;
WD31_END/WTR=JAN31_END;
-* NWD31_END/I1=WD31_END;
NADJ_END/I1=IMOD(WD31_END+1,7,'I1');
FYEND/WMDYY=JAN31_END-NADJ_END;
END
-RUN
TABLEF FILE CAR
PRINT
FYSTA
FYEND
YEAR_STA
END
WF: 8201, OS: Windows, Output: HTML, PDF, Excel
March 27, 2012, 11:27 AM
peechy23
This is absolutely great! Thank you so much. One follow up question.
What part of the code is determining how many years it runs? Ultimately I would like to be able to get the start and end dates for 60 years.
WebFOCUS 8.09 Windows, All Outputs
March 27, 2012, 11:58 AM
j.gross
quote:
What part of the code is determining how many years it runs?
Nothing explicit - the number of years in the output is the number of data instances (of MODEL) in the CAR file. (Note the WITH clause in the first Define.)
Choose a data source with a sufficient number of instances, and limit the output to 60 lines with