-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_diff_of_dates.py
36 lines (35 loc) · 1.06 KB
/
get_diff_of_dates.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
import datetime
def una():
global first
isValid=False
while not isValid:
date1 = raw_input('Input Date1 (format:MM-DD-YYYY):')
try:
first = datetime.datetime.strptime(date1, "%m-%d-%Y")
isValid=True
break
except:
print "Input Proper Date Format"
def pangalawa():
global second
isValid=False
while not isValid:
date2 = raw_input('Input Date2 (format:MM-DD-YYYY):')
try:
second = datetime.datetime.strptime(date2, "%m-%d-%Y")
isValid=True
break
except:
print "Input Proper Date Format"
una()
pangalawa()
if first > second:
diffdays = abs((first - second).days)
diffyears = diffdays / 365
diffmonths = diffdays * 0.0328767
print int(diffmonths),"Month(s) , ",diffdays,"Days(s) , ",int(diffyears),"Year(s)"
else:
diffdays = abs((second - first).days)
diffyears = diffdays / 365
diffmonths = diffdays * 0.0328767
print int(diffmonths),"Month(s) , ",diffdays,"Days(s) , ",int(diffyears),"Year(s)"