Skip to content

Instantly share code, notes, and snippets.

@ejmurray
Created February 19, 2015 08:34
Show Gist options
  • Save ejmurray/b633855bd8ec728e914b to your computer and use it in GitHub Desktop.
Save ejmurray/b633855bd8ec728e914b to your computer and use it in GitHub Desktop.
Calculates the number of days, years from a given birthday.
#!/usr/bin/python
# encoding: utf-8
'''
Calculate the number of years from the entered birthday
'''
__author__ = 'Ernest'
from datetime import date
stryear = raw_input("Enter the year you were born using four digits ")
strmonth = raw_input("Enter the month that you were born in two digits ")
strday = raw_input("Enter the day that you were born in two digits ")
intyear = int(stryear)
intmonth = int(strmonth)
intday = int(strday)
mybirhtday = date(intyear, intmonth, intday)
todaydate = date.today()
diff = todaydate - mybirhtday
numdays = diff.days
numsecs = diff.total_seconds()
numyears = numdays / 365
print "You are", numyears, "years old and", numdays, "days and ", numsecs, "seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment