Karen, I'm aware that my 30-days-ago version of the query is current time/ date specific. Good catch :-)
Thanks for the solution. I also found this one: today = datetime.datetime.today() Document.objects.filter(created_on__month=today.month, created_on__day=today.day, created_on__year=today.year) Thanks again. On Oct 12, 5:00 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Mon, Oct 12, 2009 at 5:07 PM, aa56280 <aa56...@gmail.com> wrote: > > > I have a DateTimeField called "created_on" on a model called > > "Documents". It serves as a timestamp for when the record was added. > > > I'm trying to write a query that will return all Documents created_on > > a particular date, say today. I can make it work if I look for a > > record within a range of dates... > > > <code> > > today = datetime.datetime.today() > > thirty_days_ago = today - datetime.timedelta(days=30) > > Document.objects.filter(created_on__range=(thirty_days_ago, today)) > > </code> > > > But now, I need to find records that were created on a particular > > date, like, today. > > > How do I do that? > > today_end = datetime.datetime.combine(datetime.date.today(), > datetime.time.max) > today_start = datetime.datetime.combine(datetime.date.today(), > datetime.time.min) > Document.objects.filter(created_on__range=(today_start, today_end)) > > You realize your 30-days-ago version of the query returns values that depend > on the current time as well as the current date when the query is run? This > may be rather surprising behavior for people who would likely expect the > list of things created within the last 30 days to be constant over the > course of a day (excepting things added during the day). > > 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 -~----------~----~----~----~------~----~------~--~---