On Mon, Oct 12, 2009 at 6:00 PM, phoebebright <phoebebright...@gmail.com>wrote:

>
> Try this:
>
> from datetime import date
>
> today = date.today()
>
> todays_stuff = Stuff.objects.filter(created_on = today)
>
>
Looking at the SQL that generates for a model that contains a DateTimeField,
not a DateField, I don't believe that will do what's wanted:

>>> from datetime import date
>>> today = date.today()
>>> today
datetime.date(2009, 10, 12)
>>> Document.objects.filter(created_on=today)
[]
>>> from django.db import connection
>>> connection.queries[-1]['sql']
u'SELECT `ttt_document`.`id`, `ttt_document`.`created_on`,
`ttt_document`.`name` FROM `ttt_document` WHERE `ttt_document`.`created_on`
= 2009-10-12 00:00:00  LIMIT 21'
>>>

It will only find stuff created at midnight, exactly.  (Unless the same
use-a-date-for-a-datetime technique is used when adding as well, so that the
times will always be 0, in which case it ought to be just a DateField.)

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to