forked from edooley7/dsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq5_datetime.py
49 lines (32 loc) · 1.05 KB
/
q5_datetime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Hint: use Google to find python function
####a)
from datetime import datetime
date_start = '01-02-2013'
date_stop = '07-28-2015'
t1 = datetime.strptime(date_start, '%m-%d-%Y')
t2 = datetime.strptime(date_stop, '%m-%d-%Y')
dt = t2 - t1
print('days between 1st start and stop dates =', dt.days)
####b)
date_start = '12312013'
date_stop = '05282015'
t3 = datetime.strptime(date_start, '%m%d%Y')
t4 = datetime.strptime(date_stop, '%m%d%Y')
dt = t4 - t3
print('days between 2nd start and stop dates =', dt.days)
####c)
date_start = '15-Jan-1994'
date_stop = '14-Jul-2015'
t5 = datetime.strptime(date_start, '%d-%b-%Y')
t6 = datetime.strptime(date_stop, '%d-%b-%Y')
dt = t6 - t5
print('days between 3nd start and stop dates =', dt.days)
""" Hackerrank Solution:
def difference_in_days(date1, date2):
from datetime import datetime
#date_start = '01-02-2013'
#date_stop = '07-28-2015'
t1 = datetime.strptime(date1, '%m-%d-%Y')
t2 = datetime.strptime(date2, '%m-%d-%Y')
return (t2 - t1).days
"""