how many days old am i python

+2 votes
67 views
asked Mar 11 by Lourdes Lourdes

I want to get how many days old am in using python.

print("How many days old am i")
user_dob = raw_input()

Output

How many days old am i
8/18/1993

This is what i achieved so far, I just started learning programming, and this is my first program ever, just want to display total days, hours or minutes a user has lived.

1 Answer

0 votes
answered Mar 11 by anonymous
from datetime import datetime as dt
print("How many days old am i")
user_dob = "8/18/1993" #raw_input()
user_dob_obj = dt.strptime(user_dob, "%m/%d/%Y").date()
today_date = dt.now().date()
difference = today_date - user_dob_obj
print difference.days

Output

>>> from datetime import datetime as dt
>>> print("How many days old am i")
How many days old am i
>>> user_dob = "8/18/1993" #raw_input()
>>> user_dob_obj = dt.strptime(user_dob, "%m/%d/%Y").date()
>>> today_date = dt.now().date()
>>> difference = today_date - user_dob_obj
>>> print difference.days
8606
commented May 7 by anonymous
you can easily use an online tool too without coding u can get all these time difference http://youragecalculator.com
...