Convert a date into an integer in python

I’am trying to convert a date to an integer for a comparison.

# Python3 code to calculate age in years
import datetime
from datetime import date

date_entry = input('Enter your birthdate in YYYY/MM/DD format: ')
year, month, day = map(int, date_entry.split('/'))
date1 =, month, day)

def calculateAge(birthDate):
    today =
    age = today.year - birthDate.year - \
        ((today.month, < (birthDate.month,

    return age

# Driver code
print(calculateAge(date1), "years")

if date1 < 18:
    print('You are under age')

I have an error in my if statement because date1 is not an integer.
How can I solve this?


>Solution :

you can edit as below.

if calculateAge(date1) < 18:
    print('You are under age')

enter image description here

Leave a Reply