I want to get Date on Last Thursday of next month and next of next month. Currently able to get Date of last thursday on current month.
Code:
import datetime
dt = datetime.datetime.today()
def lastThurs_currentmonth(dt):
currDate, currMth, currYr = dt, dt.month, dt.year
for i in range(31):
if currDate.month == currMth and currDate.year == currYr and currDate.weekday() == 3:
#print('dt:'+ str(currDate))
lastThuDate = currDate
currDate += datetime.timedelta(1)
return lastThuDate
lastThurs_currentmonth(dt)
Output:
datetime.datetime(2022, 11, 24, 11, 2, 17, 620842)
Now I need to get date last Thursday for next month and next of next month.
Expected Output:
date last Thursday for next month
datetime.datetime(2022, 12, 29)
date last Thursday for next of next month
datetime.datetime(2023, 1, 26)
Ref link: Get the last thursday of the current month using python