I'm trying to do the following filter in a Django query:
ben_filtro = Auditoria.objects.filter(fecha__range=[fechaInicial,fechaFinal])
I get the results but excluding some that are in the final date. Fields are of type DateTimeField
.
I'm trying to do the following filter in a Django query:
ben_filtro = Auditoria.objects.filter(fecha__range=[fechaInicial,fechaFinal])
I get the results but excluding some that are in the final date. Fields are of type DateTimeField
.
Maybe what is happening to you is that the records of the last day of fechaFinal
do not appear, this is due to the fact that if you use DateTimeField
, it automatically interpresses the days, and the time sets the time leaves it as 00:00:00
In the documentation it explains here
To include the full day in fechaFinal
, one solution may be to indicate a 23:59:59 to date, in some cases I used it as follows:
fechaFinalMax = datetime.datetime.combine(fechaFinal, datetime.time.max)
And then in the query I would use that variable fechaFinalMax
ben_filtro = Auditoria.objects.filter(fecha__range=[fechaInicial,fechaFinalMax])