Django chooses between DB dates

with _ range you can do between request

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 two dates and want to check if the date is in the het DB between the two dates

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

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

How can I run between a query to check if month = '2010-01-01' between start and end

Edit

I have suggestions in the proposal 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 
+6
source share
1 answer
 Deals.objects.filter(starting__gte=mydate, ending__lte=mydate) 

Doc here

+11
source

Source: https://habr.com/ru/post/916236/


All Articles