from datetime import datetime currentyear = 2021 currentmonth = 2 currentday = 10 def validate_age(DOB): current_date = datetime(currentyear, currentmonth, currentday) day, month, year = map(int, DOB.split('-')) dob_date = datetime(year, month, day) age_in_years = current_date.year - dob_date.year - ((current_date.month, current_date.day) < (dob_date.month, dob_date.day)) return age_in_years currentyear = 2021 currentmonth = 2 currentday = 10 def validate_age(DOB): #your code goes here b_year = int(DOB[-4:]) b_month = int(DOB[-7:-5]) b_day = int(DOB[:2]) age = currentyear - b_year if b_month > currentmonth: age -= 1 elif b_month == currentmonth: if b_day > currentday: age -= 1 return int(age)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter