Skip to content

Instantly share code, notes, and snippets.

@luabida
Last active May 21, 2024 19:50
Show Gist options
  • Save luabida/1bf60912bbbadadec19f1f691a8502da to your computer and use it in GitHub Desktop.
Save luabida/1bf60912bbbadadec19f1f691a8502da to your computer and use it in GitHub Desktop.
Calculate age
from datetime import datetime as dt
calculate_age = (
lambda bd: (
(td := dt.today()) and (td.year - bd.year - ((td.month, td.day) < (bd.month, bd.day)))
))
print(f"{calculate_age(dt(1990, 5, 21))}yo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment