Boe Jingles Boe Jingles - 1 year ago 145
Python Question

Subtracting Dates With Python

I'm working on a simple program to tell an individual how long they have been alive.

I know how to get the current date, and get their birthday. The only problem is I have no way of subtracting the two, I know a way of subtracting two dates, but unfortunately it does not include hours, minutes, or seconds.

I am looking for a method that can subtract two dates and return the difference down to the second, not merely the day.

Answer Source
from datetime import datetime

birthday = datetime(1988, 2, 19, 12, 0, 0)
diff = - birthday
print diff
# 8954 days, 7:03:45.765329
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download