P
P
PILITYXXX1232020-08-20 19:39:48
Python
PILITYXXX123, 2020-08-20 19:39:48

How to get the number of days between 2 dates?

There are two dates:

a = '2020, 03, 13'
b  = '2020, 08, 10'

We need to get the number of days between them. I tried like this:

d0 = date(data_per)
d1 = date(data_per2)
delta = d1 - d0
print(delta.days)

But it doesn't work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-08-20
@PILITYXXX123

Nobody reads the documentation...

d0 = datetime.strptime('2020, 03, 13', '%Y, %m, %d').date()

L
LXSTVAYNE, 2020-08-20
@lxstvayne

from datetime import date time
>>> a = datetime.strptime('2020, 03, 13', "%Y, %m, %d")
>>> b = datetime.strptime('2020, 08, 10', "%Y, %m, %d")
>>> print(b-a)
150 days, 0:00:00

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question