How to get first Tuesday of current month in Python?
import calendar from datetime import datetime c = calendar.Calendar(firstweekday=calendar.SUNDAY) monthcal = c.monthdatescalendar(datetime.today().year, datetime.today().month) try: tues = [day for week in monthcal for day in week if day.weekday() == calendar.TUESDAY and day.month == datetime.today().month][0] print(tues) except IndexError: print('No date found')
Output
2021-05-04