In this example, the Python datetime
module is used to calculate and output the number of days and years of a birth date.
import datetime
def calculateAge(birthday):
(d, m, y) = birthday.split('.')
return d, m, y
birthday = str(
input("Please enter your birthday in following format dd.mm.yyyy: "))
today = datetime.datetime.now()
splittedDate = calculateAge(birthday)
birthdayDate = datetime.datetime(
int(splittedDate[2]), int(splittedDate[1]), int(splittedDate[0]))
age = (today - birthdayDate).days
print(repr(age) + " days old")
print(repr(int(age/365)) + " years old")
Please enter your birthday in following format dd.mm.yyyy: 10.01.1993
10925 days old
29 years old