Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
7. Calculating differences with timedeltas


Perfect! You can also calculate the time difference between two dates. Let's try it with trip dates. How long did the following trip last?

fra_mad_scheduled =, 12, 1)
mad_fra_scheduled =, 12, 7)
trip_duration = mad_fra_scheduled - fra_mad_scheduled
print('My trip lasted for', trip_duration)


My trip lasted for 6 days, 0:00:00.

By subtracting one date from another (mad_fra_scheduled - fra_mad_scheduled), we created a timedelta in the trip_duration variable. timedeltas are objects that store time duration. In addition to doing other things, we can print them to the console. We'll talk more about timedeltas later in this part.


How much time elapsed between Daniel Higgins' first day with our company and the company's anniversary? Use the anniversary and higgins_start_day variables to find out. Print the following line:

Daniel Higgins has worked at our company for {timedelta}

Stuck? Here's a hint!

To calculate the timedelta, simply use:

anniversary - higgins_start_day