

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Pandas
incomplete
2: Data Types
incomplete
3: Extracting Data
incomplete
4: Dates and Times
incomplete
5: Datetime Math
incomplete
6: Comparing Dates
incomplete
7: List Comprehensions
incomplete
8: Dictionary Comprehensions
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Once you've parsed a date or timestamp, you usually want to do something with it. You might want to know:
How long has an order been in transit?
When should the package arrive?
That's where timedelta comes in.
Working with data is all about answering real questions. You can't do data work without a goal in mind, or you'll just be shuffling numbers around.
Subtract one datetime from another and you get a timedelta:
order_placed = datetime(2026, 5, 25, 14, 30, 0)
delivered_at = datetime(2026, 5, 29, 14, 30, 0)
difference = delivered_at - order_placed # difference is a timedelta object
print(difference.days) # the .days is... exactly what you expect
# 4You can also add or subtract a timedelta from a datetime to get a new datetime:
order_placed = datetime(2026, 5, 25, 14, 30, 0)
expected_by = order_placed + timedelta(hours=6)
print(expected_by)
# 2026-05-25 20:30:00SnackStack considers a device's reading "stale" if it stays quiet for too long.
Complete the calculate_stale_time function. It accepts a "reading_time" datetime and the maximum number of hours the device can stay silent, and returns a new datetime object representing the time when the reading will become stale.
Use the timedelta function to add max_silent_hours to the reading timestamp and return the result.