-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_calculator.py
64 lines (54 loc) · 1.3 KB
/
date_calculator.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def isleap (x):
return (x%4==0 and x%100!=0 or x%400==0)
def dopp():
leap_list=[31,29,31,30,31,30,31,31,30,31,30,31]
not_leap_list=[31,28,31,30,31,30,31,31,30,31,30,31]
m_index=mm-1
m_bf=m_index-1
d_bf=0
d_af=0
if m_bf>0:
if isleap (yy):
i=0
while i <= m_bf:
d_bf+=leap_list[i]
i+=1
else:
i=0
while i <= m_bf:
d_bf+=not_leap_list[i]
i+=1
if isleap(yy1):
i=mm1
mo=leap_list[i-1]
while i<= 11:
d_af+=leap_list[i]
i+=1
else:
i=mm1
mo=not_leap_list[i-1]
while i <= 11:
d_af+=not_leap_list[i]
i+=1
dd2=mo-(dd1-1)
d3=dd-1
day_chop=d_bf+d_af+d3+dd2
j=yy
sum_year=0
while j <= yy1:
if isleap(j):
sum_year+=366
else:
sum_year+=365
j+=1
total_days=sum_year-day_chop
return(total_days)
dob =input("dob in ddmmyyyy format: ")
dd = int(dob[:2])
mm = int(dob[2:4])
yy= int(dob[4:])
tod= input("today's date in ddmmyyyy format: ")
dd1 = int(tod[:2])
mm1 = int(tod[2:4])
yy1= int(tod[4:])
print("days since birthday",dopp())