Advertisement
DeaD_EyE

birthday -> age in yeas and days left to next birthday

Jul 8th, 2021
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import datetime
  2. from collections import namedtuple
  3.  
  4. Result = namedtuple("bithday", "years days_left")
  5.  
  6. def bcounter(bday: datetime.date) -> Result:
  7.     day = datetime.timedelta(days=1)
  8.     today = datetime.date.today()
  9.     years = today.year - bday.year
  10.     bday = bday.replace(year=today.year)
  11.     if today < bday:
  12.         years -= 1
  13.     return Result(years, int(abs(bday - today) / day))
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement