Skip to content

Instantly share code, notes, and snippets.

@lppier
Last active December 26, 2018 03:38
Show Gist options
  • Save lppier/a9f61814037a43a1c4127f3eceb4451a to your computer and use it in GitHub Desktop.
Save lppier/a9f61814037a43a1c4127f3eceb4451a to your computer and use it in GitHub Desktop.
first monday of month
from datetime import date
from dateutil.relativedelta import relativedelta, MO
# Relative delta replaces the day in the date you specify by day = 1. From this new date, weekday=MO(+1) specifies the 1st Monday.
def get_first_mon_of_mth(dt):
print (dt + relativedelta(day=1, weekday=MO(+1)))
get_first_mon_of_mth(date(2018, 12, 30))
get_first_mon_of_mth(date(2019, 6, 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment