Last active
November 23, 2023 22:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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