Date arithmetic with timedelta
Once dates are real date or datetime values you can do math with them. timedelta represents a span of time. Add it to shift dates forward or backward, and subtract two dates to get the gap between them.
Once your dates are real datetime objects you can do math with them. The timedelta class represents a span of time, like 7 days or 90 minutes. Add it to shift dates around.
Build a timedelta and add it to a date:
timedelta accepts several keyword arguments. Pass any combination, including fractional values:
What will be the output?
Use a negative timedelta, or just subtract, to go backwards in time:
What will be the output?
Subtract two date or datetime objects and you get a timedelta describing the gap. Read .days off it for an integer number of days.
Compute how many days between two dates:
What will be the output?
Datetimes work the same way. Add a timedelta with hours and minutes to shift the time of day too.
A flight leaves at 14:00 and lasts 7h30m:
What will be the output?
What will be the output?
What will be the output?
What will be the output?