age calculator

from datetime import datetime def calculate_detailed_age(dob_str): # Convert string to datetime object dob = datetime.strptime(dob_str, "%Y-%m-%d") now = datetime.now() # Total time difference delta = now - dob # Breakdown calculations total_seconds = int(delta.total_seconds()) total_minutes = total_seconds // 60 total_hours = total_minutes // 60 total_days = delta.days total_weeks = total_days // 7 # For accurate years and months years = now.year - dob.year months = now.month - dob.month days = now.day - dob.day if days < 0: months -= 1 days += (dob.replace(month=dob.month % 12 + 1, day=1) - dob.replace(day=1)).days if months < 0: years -= 1 months += 12 # Print detailed age print(f"🔢 Detailed Age Calculation:") print(f"🗓️ Years: {years}") print(f"📆 Months: {months}") print(f"🧮 Weeks: {total_weeks}") print(f"📅 Days: {total_days}") print(f"⏰ Hours: {total_hours}") print(f"🕒 Minutes: {total_minutes}") print(f"⏱️ Seconds: {total_seconds}") # Example usage dob_input = input("Enter your Date of Birth (YYYY-MM-DD): ") calculate_detailed_age(dob_input) 🔢 Detailed Age Calculation: 🗓️ Years: 35 📆 Months: 4 🧮 Weeks: 1834 📅 Days: 12840 ⏰ Hours: 308160 🕒 Minutes: 18489600 ⏱️ Seconds: 1109376000

Post a Comment

0 Comments