finding the start date end day in python

Viewed 15
S = dt.datetime(2022, 3, 2).date()
E = dt.date(2023, 7, 31)
startyear = S.year
startmonth = S.month
while (startyear, startmonth) <= (E.year, E.month):
    print(dt.date(startyear, startmonth, 1))
    if startmonth == 12:
        startyear = startyear + 1
        startmonth = 1
    else:
        startmonth = startmonth + 1

here I get the start date month year but I want end day of the month

this is how I got the answer

2022-03-01
2022-04-01
2022-05-01
2022-06-01
2022-07-01
2022-08-01
2022-09-01
2022-10-01
2022-11-01
2022-12-01
2023-01-01
2023-02-01
2023-03-01
2023-04-01
2023-05-01
2023-06-01
2023-07-01

if anyone knows please answer me

I want the output end of the day in a month

Sample Input: 02/12/2022, 24/02/2023 (Check and validate the start , end dates)
Sample Output:
[
            {'year': 2022, 'month': 'Dec', 'start_date': "01/12/2022", 'end_date': "31/12/2022", 'days': 31},
            {'year': 2023, 'month': 'Jan', 'start_date': "01/01/2022", 'end_date': "31/01/2023", 'days': 31},
            {'year': 2023, 'month': 'Feb', 'start_date': "01/02/2022", 'end_date': "28/02/2023", 'days': 28}  
]
0 Answers
Related