Working with Date and Time
Dateutil provides extensions to the methods already available in datetime
and includes features for processing raw data.
Dateutil is divided into several subclasses:
- easter — used to calculate the date and time based on different calendars, specifically: Western, Orthodox, and Julian.
- parser — includes an advanced date and time parser, allowing us to parse various formats.
- relativedelta — designed for replacing components of a date.
Additionally, it's worth mentioning utils, which contains basic functions for working with date and time.
from datetime import datetime
from dateutil.relativedelta import relativedelta
# Current time
dt_now = datetime.now()
print(dt_now)
# Next month
print(dt_now + relativedelta(months=+1))
# Next month, plus two weeks, at 13:00.
print(dt_now + relativedelta(months=+1, weeks=+2, hour=17))
# Calculating age
birthday = datetime(2000, 1, 1, 1, 1)
print(relativedelta(dt_now, birthday))
Page of .
Leave a comment
You must be logged in to leave a comment.
Log in or
sign up to join the discussion.
Comments (0)