Answer the question
In order to leave comments, you need to log in
How to calculate from date to date?
Krch date
07/31/2017
We need to calculate until now the
output in the format
Years months days have passed
I know that it's easy, but I have errors in my calculations,
please help
Answer the question
In order to leave comments, you need to log in
>>> 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 {diff.days} days'
'2 years, 8 months and 17 days'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question