I have a list of dates that is in datetime.date format (year, month, day).
I want to know the position that has a datex (which also has the format datetime.date (year, month, day) in the list with the following code: posicion = lista.index(fechax)
.
python throws me the error:
ValueError: datetime.date (year, month, day) is not in list
The issue is that both the list and the date searched have the same format and I made sure that datex was on the list of course.
What could be happening? or does the function the index method not work with dates?
EDIT:
Wb = load_workbook(filename = 'C:\ICP.xlsx')
sheet_ranges = wb["Simple"]
fecha_icp=[(c.value).date() for c in sheet_ranges['A'][3:3804]]#.date() no agrega tiempo solo la fecha.
With this code I get dates from an excel where they are with date format. to build the list I read the value with .date () to not add hours or minutes.
As you can see in the image, it's what the list looks like in python. then I occupy this code: v = icp_value.index(valuation_date)
.
the variable valuation_date the entry like this:
valuation_date= input('ingrese la fecha de valorizacion en formato yyyy-mm-dd')# ingresar fecha de contrato
valuation_date= dt.datetime.strptime(valuation_date.rstrip(), "%Y-%m-%d").date()
and in python it looks like this:
As you can see, the date sought and the list have the same format and the formula does not work.
I leave the excel: link
regards,