﻿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
9596	Add a __date lookup for DateTimeField	django@…	Tim Graham <timograham@…>	"Many times dates are stored in datetime fields even though the majority of lookup operations are going to be based on dates without times.

I am proposing a _''_''date field lookup to make it easier to compare a !DateTimeField to a date.

In plain SQL this is very easy; in Mysql/Sqlite it is just ""date(fieldname)"". The reason I mention this is not to indicate that it would be possible to make Django do it (though it is, and I will), but because it struck me that the operation is much more obscure using the Django DB layer than it is writing in plain SQL. For example, this is how it is done in django.views.date_based:

{{{ {'date_field__range': (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} }}}

And the way I am proposing:

{{{ {'date_field__date': date} # date is a datetime.date object }}}

I have attatched a patch which alters three files and makes this work under Sqlite, and should also make it work under MySQL, however it implementation is by no means thorough. If this is deemed a good idea I will look into improving it.

Another idea is to allow comparing DateTimeFields to arbitrary length tuples which are in the format (YYYY, MM, DD, HH, MM, SS), but are between 1 and 6 elements long... So that for example I could do:

{{{ {'date_field': date.timetuple()[:2]} }}}

And that would be true if the date was the same month."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	lookup_type date datetimefield compare comparison query_term field lookup	jarek.zgoda@… flosch@… hv@… JMagnusson curtis@… jon.dufresne@…	Accepted	1	0	0	0	0	0
