About Me

header ads

test age calculator

import datetime def calculate_age(born): today = datetime.datetime.now() age = today - born years = age.days // 365 months = (age.days % 365) // 30 weeks = (age.days % 365) // 7 days = age.days % 365 % 7 hours = age.seconds // 3600 minutes = (age.seconds % 3600) // 60 seconds = age.seconds % 60 next_birthday = datetime.datetime(today.year, born.month, born.day) if today < next_birthday: remaining_days = (next_birthday - today).days else: next_birthday = datetime.datetime(today.year + 1, born.month, born.day) remaining_days = (next_birthday - today).days print("Age:") print(f"{years} years, {months} months, {weeks} weeks, {days} days, {hours} hours, {minutes} minutes, {seconds} seconds") print(f"Next birthday in {remaining_days} days") birth_date = datetime.datetime(1990, 1, 1) calculate_age(birth_date)

Post a Comment

0 Comments