If frequency is Monthly. I need to extract the subject like For the Month of December 2023.
If I will run in January 2024 need to extract only Dec 2023.
For example I will run in March 2024 the subject will be For the Month of February 2024.
Need to extract Feb 2024 dynamically.
If frequency is Quarterly and I will run the flow in 1,4,7,10 months only and Subject like this For Q4, October through December 2023.
If I will in 1(January)in the subject need to Q4.
If run in 4 month bot need to extract Q1
Like this
Need to extract Q1, Q2, Q3 and Q4 based on Bot run in the month .
If frequency is Annually.
If I will run in January 2024 subject like this For January to December 2023.
Form that I need to extract Jan to Dec 2023
If I will run in Feb need to extract Fec to Jan 2024.
Without doing your homework and providing a complete solution, a few tips on how I would approach this.
I see 3 different sub-use cases, so lets peel them off one by one.
given any month, you need to know the month before it.
So I could use the current date/input date, and simply use myInputDate.AddMonths(-1). This will calculate a new date, so it automatically takes care of changing years if you go from Jan → Dec
Here you have 2 desired dates, indicating the range of the quarter. So DateStart and DateEnd. DateEnd is easy, that is by default DateStart + 2 months (assuming we focus only on the months.
Determining the start date I would first calculate the 1st month of the quarter of the input date. You can do this by a full calculation, but since a year only has 12 months for the foreseeable future you could also just create a small static collection of the months per quarter.
Once you know the first month of the input quarter, the report start date is by default substracting 3 months from that date, turning Jan '23 into Oct '22. Then end date then Dec 22 by adding 2.
this one a combination of both. You know the input month. The end date is input month -1. the start date is the end date -11 (or input minus 12 whichever you prefer.
By using proper date/time datatypes these calculations allow you to derive month and year at your leisure.