﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16023	Range query on a datetime is NOT inclusive with dates	jodym@…	Aymeric Augustin	"I'm using a range test as part of a QuerySet on a DateTimeField.  Based on the documentation, I expect this to be inclusive, but if I pass in a datetime.date it is not.  

Here's a simple example:

{{{
# models:
class Transaction(models.Model):
    posted = models.DateTimeField()

# views:
    start_date = datetime.date(2011, 4, 1)
    end_date = datetime.date(2011, 4, 30)
    t = Transaction.objects.filter(posted__range=(start_date, end_date))
    # t does NOT contain transactions posted on 2011-04-30, despite range being ""inclusive"".
}}}

Printing t.query reveals:
{{{
SELECT ""datebug_transaction"".""id"", ""datebug_transaction"".""posted"" FROM ""datebug_transaction"" WHERE ""datebug_transaction"".""posted"" BETWEEN 2011-04-01 00:00:00 and 2011-04-30 00:00:00
}}}
The conversion to a 00:00:00 datetime.datetime occurs at:

{{{
django/db/models/fields/__init__.py(682)to_python()
--> 682         if isinstance(value, datetime.date):
    683             return datetime.datetime(value.year, value.month, value.day)
}}}

The time part needs to be 00:00:00 for the start of the range and 23:59:59.999999 for the end."	Bug	closed	Documentation	1.4	Normal	invalid			Accepted	0	0	0	0	0	0
