About Date Operations

To get specific weekday of every month, you can use relativedelta from dateutils. For example, so you could get the usual day for Django meetup in Berlin which happened to be every second to the last Tuesday of the month:

1
(env)$ pip install python-dateutil

Then write this Python code:

1
2
3
4
5
6
7
8
from datetime import date, timedelta
from dateutil.relativedelta import relativedelta, TU
# the first day of the month
first = date.today().replace(day=1)
# the last day of the month
last = first + relativedelta(months=1) - timedelta(days=1)
# the second to the last Tuesday of the month
tuesday = last + relativedelta(weekday=TU(-2))

Tips and Tricks Programming Development Python 3