1
In the date variable, you are receiving several dates in string
as array
, want to bring the smallest
cont = 0
menor_data = datetime.strptime('31/12/2300', '%d/%m/%Y')
while cont < len(datas):
data_d = datetime.strptime(datas[cont], '%d/%m/%Y').date()
if data_d < menor_data:
menor_data = data_d[cont]
cont = cont + 1
print(menor_data)
Returns the following error:
Traceback (Most recent call last):
in
if data_d < menor_data:
Typeerror: can’t compare datetime.datetime to datetime.date
In this case, the error message tells you exactly what is happening. I do not know if it is productive a complete answer - the connection is that you try to read the error message. If you don’t even know English, use an automatic translator (but it can get worse, since the translator won’t know what a class name is and what a phrase is)
– jsbueno
in your variable menor_data tries to put the method . date() to return the same type you are creating inside while. They must be of the same type, or datetime or date.
– Marlysson
I understand the message, but was not seeing that the missing . date(), Thanks!
– DaniloAlbergardi
@Marlysson I suggest you write your comment as an answer so that the OP can accept your answer, and so mark the question as answered.
– dot.Py
@dot. Py Blz. As suggested I put my comment as response, if it helped solve the problem mark it as correct for further queries.
– Marlysson