Dates ===== .. contents:: :local: Introduction ------------ The ``date`` data type is a **non built-in data type**, but part of the standard library. Thus, to be able to use it, it has to be imported first. Exercise 1 - Calculating the duration between dates --------------------------------------------------- .. interactive_code_block:: :caption: Calculate the duration in days between two dates from datetime import date release_date = date(1991, 2, 20) # Release date of the first version of Python today = date.today() duration = today - release_date print('The first version of Python has been released {} days ago.'.format(duration.days)) Exercise 2 - Calculating the sum of a date and a duration --------------------------------------------------------- .. interactive_code_block:: :caption: Calculate the sum of a date and a duration from datetime import date, timedelta release_date = date(1991, 2, 20) # Release date of the first version of Python duration = timedelta(days = 10_000) calculated_date = release_date + duration print('On {} the first version of Python has been released {} days ago.'.format(calculated_date, duration.days))