Skip to content

Instantly share code, notes, and snippets.

@Jawschamp
Last active November 23, 2023 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jawschamp/10dc6f12cc2d72974454a0d324ddb588 to your computer and use it in GitHub Desktop.
Save Jawschamp/10dc6f12cc2d72974454a0d324ddb588 to your computer and use it in GitHub Desktop.
Not anything elaborate but some challenged me to do this in like 5 mins so I did
import datetime
def get_time_remaining_until_birthday(dob_m: int, dob_d: int, dob_y: int):
today = datetime.datetime.now()
birthday = datetime.datetime(today.year, dob_m, dob_d)
if birthday < today:
birthday = birthday.replace(year=today.year + 1)
delta = birthday - today
return (delta.days // 30, delta.days % 30, today.year - dob_y + 1)
delta = birthday - today
return (delta.days // 30, delta.days % 30, today.year - dob_y)
date = get_time_remaining_until_birthday(12, 17, 2002)
print(date)
print(f"Remaining time until you turn {date[2]} is {date[0]} months & {date[1]} day(s)")
@Jawschamp
Copy link
Author

This new update accounts for if your birthday already passed this year, and it calculates the age you will be.
get_time_remaining_until_birthday(dob_m: int, dob_d: int, dob_y: int)
returns type tuple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment