Compare dates in an array?

1

In the variable dates, you are receiving several dates in string as array , I want to bring the smaller

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 not compare datetime.datetime to datetime.date

    
asked by anonymous 27.03.2017 / 01:20

1 answer

2

In your variable menor_data try to put the .date() method to return the same type you are creating within the while.

They must be of the same type, or datetime or date .

    
29.03.2017 / 14:29