7

with _range you can do a between query

start_date = datetime.date(2005, 1, 1)
end_date = datetime.date(2005, 3, 31)
Entry.objects.filter(pub_date__range=(start_date, end_date))

You can use this if you have 2 dates and want to check if the date in het DB is between those 2 dates

In my case I have 1 date and want to check if that date is between my 2 date fields in db

class Deals(models.Model):
    #stuff
    starting = models.DateField()
    ending = models.Datefield()

How can I do a between query to check if month = '2010-01-01' is between starting and ending

Edit

I have deals in de Deals table. I want to know if there is a deal in January 2010(2010-01-01), February 2010(2010-02-01), etc

Like this

SELECT * FROM deals WHERE '2010-01-01' BETWEEN starting AND ending 
2
  • Checking if a month is between a particular start/end doesn't require a query. Do you actually mean you want to find the Dates instance(s) where month is between starting and ending? Commented May 21, 2012 at 10:08
  • I edited the topic. I need to find deals that apply for each month of a certain year. Hope it's clear Commented May 21, 2012 at 10:17

1 Answer 1

11
Deals.objects.filter(starting__gte=mydate, ending__lte=mydate)

Doc is here

Sign up to request clarification or add additional context in comments.

2 Comments

So i don't have to use between. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.