OK, but Django do not provide 'time' lookup so my problem is 'how to
retrieve time part of datetime field in a query'

On 31 Mar, 04:29, Brian Neal <bgn...@gmail.com> wrote:
> On Mar 30, 10:12 am, LD <l.dzied...@gmail.com> wrote:> Hi,
>
> > I don't have idea how to do simple task.
> > I have model with DateTimeField and I want to retrieve all objects
> > that have time for example lower than 2pm.
>
> > I know about Django queryset lookup like year, month, day. Is there
> > something similar but for time? If not what is the simplest way to
> > accomplish that?
>
> > So it would be great to do something like this:
> > MyModel.objects.filter(date_field__time__lt == datetime.time(14,0))
> > assuming of course that MyModel.date_field is models.DateTimeField
>
> Well, the model field is storing a date and a time. So you can't just
> compare that against a time, I don't think. You need to pick a day and
> a time. And then you can do the filtering, you've almost got the
> syntax right. Something like this should work:
>
> MyModel.objects.filter(date_field__time__lt=datetime.datetime.(yy, mm,
> dd, 14, 0))
--~--~---------~--~----~------------~-------~--~----~
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