This short python app asks the user for their year, date and month of birth, and passes them through the datetime module to create a correctly formatted date. Then the App tells the user how many days to or since their birthday in the current year, or alternately wishes them a happy birthday!
Code
import datetime
def print_header():
print('----------------------------------------------')
print(' BIRTHDAY APP')
print('----------------------------------------------')
print()
def get_birthday_from_user():
print("When were you born? ")
year = int(input("Year [YYYY]: "))
month = int(input("Month [MM]: "))
day = int(input("Day [DD]: "))
birthday = datetime.date(year, month, day)
return birthday
def compute_days_between_dates(original_date, target_date):
this_year = datetime.date(target_date.year, original_date.month, original_date.day)
dt = this_year - target_date
return dt.days
def print_birthday_information(days):
if days < 0:
print("You had your birthday {} days ago this year".format(-days))
elif days > 0 :
print("It is your birthday in {} days".format(days))
else:
print("Happy Birthday!!!!")
def main():
print_header()
bday = get_birthday_from_user()
now = datetime.date.today()
number_of_days = compute_days_between_dates(bday, now)
print_birthday_information(number_of_days)
main()
Screenshot

Join the conversation: