Current Age Calculator by Date of Birth with Python

Photo by Nick Stephenson on Unsplash
from datetime import datetime, timedelta

# Get the current date
now = datetime.now()

# Ask the user for their date of birth
print("Enter your date of birth (YYYY-MM-DD):")
dob_input = input()

# Parse the user's input into a datetime object
birthday = datetime.strptime(dob_input, "%Y-%m-%d")

# Calculate the difference between the current date and the birthday
difference = now - birthday

# Calculate the person's age in years
age_in_years = difference.days // 365

print(f"You are {age_in_years} years old.")
Minions

--

--

🎯 Security Researcher | Bug Bounty Hunter | Exploit Development | DAST & SAST | Chess Player | Code is Life | 0xBUFFDEAD | Advisor 🎯

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ismail Tasdelen

🎯 Security Researcher | Bug Bounty Hunter | Exploit Development | DAST & SAST | Chess Player | Code is Life | 0xBUFFDEAD | Advisor 🎯