I am trying to subtract two dates or days from today's date. I want to get the result in years, months, days. How to do that?
Expecting 1 year, 2 months, 5 days
, 20 days
, 3 months, 2 days
ago, etc. instead of just days.
import datetime
import pytz
tz='US/Pacific'
birthday = datetime.datetime(2020, 2, 19, 12, 0, 0)
>>> import datetime
>>> import pytz
>>> tz='US/Pacific'
>>> birthday = datetime.datetime(2020, 2, 19, 12, 0, 0)
>>> diff = datetime.datetime.now() - birthday
>>>
>>> diff
datetime.timedelta(days=326, seconds=39130, microseconds=319509)
>>>
>>> birthday = datetime.datetime(2015, 2, 19, 12, 0, 0)
>>> diff = datetime.datetime.now() - birthday
>>> diff
datetime.timedelta(days=2152, seconds=39151, microseconds=823846)
>>>
>>> diff.days
2152