from datetime import datetime
from datetime import date
from dateutil.relativedelta import relativedelta
import calendar
import dateutil
# next month
today = date.today() # date
today_next_month = today + relativedelta(months=+1) # date
display(today, today_next_month) # datetime.date(2022, 3, 21), datetime.date(2022, 4, 21)
now = datetime.now() # datetime
now_next_month = now + relativedelta(months=+1) # datetime
display(now, now_next_month) # datetime(2022, 3, 21, 12, 35, 46, 824401), datetime(2022, 4, 21, 12, 35, 46, 824401)
datetime.date(2022, 3, 21)
datetime.date(2022, 4, 21)
datetime.datetime(2022, 3, 21, 13, 21, 45, 506740)
datetime.datetime(2022, 4, 21, 13, 21, 45, 506740)
# time difference
delta = relativedelta(datetime(2003, 10, 24, 10, 0), today)
# next weekday
today+relativedelta(weekday=calendar.FRIDAY) # date
today+relativedelta(weekday=dateutil.relativedelta.FR(+1)) # date
datetime.date(2022, 3, 25)
date(2003, 10, 1)+relativedelta(yearday=260)
datetime.date(2003, 9, 17)
from dateutil.parser import *
# ISO format
parse("2003-09-25T10:49:41.5-03:00")
parse("20030925T104941")
datetime.datetime(2003, 9, 25, 10, 49, 41)
# AM and PM
parse("10h am")
parse("12:00pm")
datetime.datetime(2022, 3, 21, 12, 0)