Lets assume we had started a new vertical in Jan 2020, so according to the vertical's calendar Jan is 1st month, Feb = 2.. Dec = 12 & Jan 2021 = 13th month. Our vertical's financial calendar starts from Feb.
Ex 1:
So my requirement is suppose If I run this code today/or any other date (May 2023, which is 41st month according to vertical's calendar)
My output should be = (41,40,39,38)
41 is my current month in this FY &
38 is Feb month of this current FY
Ex 2:
Input = Jan 2023
Output = (37,36,35,34,33,32,31,30,29,28,27,26)
Jan is 37th month &
Feb is 26th month of last FY.
This should be implemented in Python. TIA
from datetime import date
current_date = date(2023,1,1)
feb_2020 = date(2020, 1, 1)
current_year = current_date.year
if current_date.month<2:
current_year-=1
current_feb = date(current_year,2,1)
# Calculate the difference between the current month and February 2020
month_diff_current = (current_date.year - feb_2020.year) * 12 + (current_date.month - feb_2020.month)+1
month_diff_feb = (current_feb.year - feb_2020.year) * 12 + (current_feb.month - feb_2020.month)
output =[i for i in range(month_diff_current,month_diff_feb,-1)]
print(output)
Here your full solution.