
11. Creating timedeltas


Amazing work! We get a timedelta when we subtract one datetime object from another, but we can also create a timedelta ourselves and add it to or subtract it from a datetime to get another datetime object. Examine the code snippet below:

fra_mad_1_Dec = datetime.datetime(2018, 12, 1, 9, 45, 0)
delta_1_day = datetime.timedelta(days=1)
fra_mad_2_Dec = fra_mad_1_Dec + delta_1_day

Result: 2018-12-02 09:45:00

When we create a timedelta, we don't need to provide all the elements (e.g., hours or microseconds). It's enough to provide only the parts we need. In this case, we wanted to have a timedelta of one day, so we simply wrote datetime.timedelta(days=1). When we add this timedelta to our December 1st datetime, we get a new datetime of December 2nd.


As you can see in the template code, the "Goals for 2019" meeting started at 3:45 PM on October 9th, 2018. The meeting lasted for 45 minutes. Your task is to calculate when the meeting ended and print the following sentence:

"Goals for 2019" started at {start datetime} and finished at {finish datetime}

Name the timedelta object meeting_duration.

Stuck? Here's a hint!

Create a timedelta using:

meeting_duration = datetime.timedelta(minutes=45)

Then add the delta to goals_for_2019 to get the finish time.