-
Notifications
You must be signed in to change notification settings - Fork 55
/
age_in_days.py
50 lines (49 loc) · 1.48 KB
/
age_in_days.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
""" project for final week done with basic course """
import datetime
# would help in finding no.of days
def days_in_month(yeara,montha):
if(montha==2 and yeara%4==0):
days=29
elif(montha==2 and yeara%4!=0):
days=28
elif(montha<=7 and montha%2 !=0):
days=31
elif(montha<=7 and montha%2 ==0):
days=30
elif(montha>7 and montha%2 ==0):
days=31
else:
days=30
return days
def is_valid_date(yearb,monthb,dateb): # help in checking a valid date
if( 1<=yearb<=9999)and(1<=monthb<=12)and(1<=dateb <= days_in_month(yearb,monthb)):
return True
else :
return False
def days_between(year,month,date,year1,month1,date1):
# help in checking a valid date
if(is_valid_date(year,month,date))and(is_valid_date(year1,month1,date1)) :
difference=0
else :
return 0
date11=datetime.date(year,month,date)
date22=datetime.date(year1,month1,date1)
difference = date22-date11
if(difference.days>0):
return difference.days
else:
return 0
def age_in_days(yearc,monthc,datec):
# help in checking a valid date
if(is_valid_date(yearc,monthc,datec)):
difference=0
else:
return 0
todays_date=datetime.date.today()
date33=datetime.date(yearc,monthc,datec)
difference=todays_date-date33
if(difference.days>0):
age=difference.days
else :
age= 0
return age