Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Time
Date
Datetime
12. Comparing datetimes
Summary

Instruction

Great job! We can also use the following operators to compare datetime objects: >, >=, <, <=, ==. Let's see this in action:

fra_mad_1_Dec_boarding_time = datetime.datetime(2018, 12, 1, 8, 15, 0)
arrival_datetime = datetime.datetime(2018, 12, 1, 10, 7, 0)
if (arrival_datetime > fra_mad_1_Dec_boarding_time):
  print('You are late for your flight!')
else:
  print('You are on time for your flight, proceed to the boarding gate.')

In Python, datetime_a > datetime_b is True when datetime_a is a later (more recent) point in time than datetime_b.

Exercise

Modify the starts_in(start_datetime) function that you wrote two exercises ago – add some code to return a timedelta of 0 if the meeting has already started.

Stuck? Here's a hint!

To return a timedelta with a zero duration, simply use return datetime.timedelta(0).