datetime.timedelta()
datetime.timedelta() is a Python function in the Datetime Module category. Represents a duration, the difference between two dates or times. The syntax is datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0). Parameters: days, seconds, microseconds, etc.. Returns: Timedelta object. A typical example: from datetime import timedelta
d = timedelta(days=7, hours=3)
print(d) # "7 days, 3:00:00". A close sibling is datetime.date(), which creates a date object representing a specific date (year, month, day). A close sibling is datetime.date.today(), which returns the current local date. A close sibling is datetime.datetime.now(), which returns the current local date and time with optional timezone. A close sibling is datetime.datetime.utcnow(), which returns the current UTC date and time (deprecated, use now(timezone.utc)). More about this category: Date and time handling — date, datetime, timedelta, timezone. For a broader walkthrough, read the Datetime Module guide. Related Datetime Module entries: datetime.date(), datetime.date.today(), datetime.datetime.now(), datetime.datetime.utcnow(), datetime.datetime.fromtimestamp(), datetime.datetime.strptime().