![]() |
VOOZH | about |
The datetime.timedelta() function in Python is used to represent a time difference. It allows you to add or subtract days, hours, minutes or seconds from a date or datetime object.
Example: This code gets the current date and time using datetime.now() and then uses timedelta(days=1) to calculate the date and time one day in the future.
2026-01-09 09:58:19.083495
Explanation:
datetime.timedelta(days=0, seconds=0, minutes=0, hours=0, weeks=0)
Parameters:
Example 1: This example shows how to add days to the current date using timedelta().
2026-01-13 10:02:23.079919
Explanation: timedelta(days=5) adds 5 days to d
Example 2: This example demonstrates how to go back in time by subtracting hours.
2026-01-08 08:03:36.816373
Explanation: timedelta(hours=2) subtracts 2 hours from t
Example 3: This example calculates the time difference between two datetime values.
3 days, 0:00:00
Explanation: d2 - d1 returns a timedelta showing the time gap