Last active
December 26, 2018 03:38
-
-
Save lppier/a9f61814037a43a1c4127f3eceb4451a to your computer and use it in GitHub Desktop.
first monday of month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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