If I have a hard coded date, how can I compare it to a date that is given by the user?
I want to eventually compare a persons birthday to see how old they are. Can someone point me in the right direction?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll want to use Python’s standard library
datetimemodule to parse and convert the “date given by the user” to adatetime.dateinstance and then subtract that from the current date,datetime.date.today(). For example:ageis adatetime.timedeltainstance, and the 11397 is their age in days (available directly viaage.days).To get their age in years, you could do something like this: