Python returns age based on birth date

From , 5 Years ago, written in Python, viewed 90 times.
URL https://pastebin.vip/view/a2487e89
  1.     def CalculateAge(self, Date):
  2.         '''Calculates the age and days until next birthday from the given birth date'''
  3.         try:
  4.             Date = Date.split('.')
  5.             BirthDate = datetime.date(int(Date[0]), int(Date[1]), int(Date[2]))
  6.             Today = datetime.date.today()
  7.    
  8.             if (Today.month > BirthDate.month):
  9.                 NextYear = datetime.date(Today.year + 1, BirthDate.month, BirthDate.day)
  10.             elif (Today.month < BirthDate.month):
  11.                 NextYear = datetime.date(Today.year, Today.month + (BirthDate.month - Today.month), BirthDate.day)
  12.             elif (Today.month == BirthDate.month):
  13.                 if (Today.day > BirthDate.day):
  14.                     NextYear = datetime.date(Today.year + 1, BirthDate.month, BirthDate.day)
  15.                 elif (Today.day < BirthDate.day):
  16.                     NextYear = datetime.date(Today.year, BirthDate.month, Today.day + (BirthDate.day - Today.day))
  17.                 elif (Today.day == BirthDate.day):
  18.                     NextYear = 0
  19.  
  20.             Age = Today.year - BirthDate.year
  21.  
  22.             if NextYear == 0: #if today is the birthday
  23.                 return '%d, days until %d: %d' % (Age, Age+1, 0)
  24.             else:
  25.                 DaysLeft = NextYear - Today
  26.                 return '%d, days until %d: %d' % (Age, Age+1, DaysLeft.days)
  27.         except:
  28.             return 'Wrong date format'
  29.  
  30.  
  31. #//python/8460

Reply to "Python returns age based on birth date"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website