forked from ZetechUni/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_date.py
More file actions
18 lines (14 loc) · 741 Bytes
/
input_date.py
File metadata and controls
18 lines (14 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# import the datetime and timedelta modules
from datetime import datetime, timedelta
# When you ask a user for a date tell them the desired date format
birthday = input('When is your birthday (dd/mm/yyyy)? ')
# When you convert the string containing the date into a date object
# you must specify the expected date format
# if the date is not in the expected format Python will raise an exception
birthday_date = datetime.strptime(birthday, '%d/%m/%Y')
print ('Birthday: ' + str(birthday_date))
# Because we converted the string into a date object
# We can use date and time functions such as timedelta with the object
one_day = timedelta(days=1)
birthday_eve = birthday_date - one_day
print('Day before birthday: ' + str(birthday_eve))