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:

(env)$ pip install python-dateutil

Then write this Python code:

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

Django/Python Consulting

If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.