How to calculate from date to date?

KRC date
31.07.2017
It is necessary to calculate up to the present time
the output
Years months days
I know it's easy but I'm in the calculations of the error
please help
April 19th 20 at 12:26
1 answer
April 19th 20 at 12:28
Solution
>>> import datetime
>>> from dateutil import relativedelta
>>> past_date = '2017-07-31'
>>> past_date = datetime.datetime.strptime(past_date, '%Y-%m-%d')
>>> today = datetime.datetime.now()
>>> diff = relativedelta.relativedelta(today, past_date)
>>> f'{diff.years} years, {diff.months} months and {the diff.days} days'
'2 years, 8 months and 17 days'

Find more questions by tags Python