prateek
prateek

Reputation: 3

Retrieving date from a datetime column in python/django

I have a column in my database which is named date... in this column i am storing a datetime value...now when i want to filter the table according to date value(only date and not datetime)..say i want to retrieve all coloums having a particular date..then how can i apply such filtering(i.e getting date out of datetime column)

Upvotes: 0

Views: 158

Answers (2)

Matthew Schinckel
Matthew Schinckel

Reputation: 35619

You can also do:

MyModel.objects.filter(date__gte=date, date__lt=date+datetime.timedelta(1))

Not sure which is faster, this or dappawit's solution.

Upvotes: 0

dappawit
dappawit

Reputation: 12570

For example, to match March 18, 2011:

queryset = MyModel.objects.filter(date__year=2011, date__month=3, date__day=18)

Django docs: http://docs.djangoproject.com/en/1.2/ref/models/querysets/#year

Upvotes: 1

Related Questions