from datetime import date def years birthday today date today year tod

 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
from datetime import date
def years(birthday):
today = date.today()
year = today.year - birthday.year
if today.month < birthday.month:
year -= 1
elif date.month == birthday.month and today.day < birthday.day:
print today.day, birthday.day
year -= 1
print year
birthday1 = date(1984, 5, 6)
birthday2 = date(1984, 6, 25)
birthday3 = date(1984, 6, 30)
birthday4 = date(1984, 7, 25)
map(years, (birthday1, birthday2, birthday3, birthday4))
############################
[offline@jobber download]$ vim birthday.py
[offline@jobber download]$ python birthday.py
24
24
24
23
[offline@jobber download]$ date
Sun Jun 29 23:15:09 IDT 2008