Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:32:31+00:00 2026-06-07T23:32:31+00:00

Is it possible to do a QuerySet filter that returns object form a specified,

  • 0

Is it possible to do a QuerySet filter that returns object form a specified, recurring time span?

For example, given a start and an end date a few days apart, I would like to be able to find:

  • Get all objects with timestamp between 2pm and 7pm for every day between start and end
  • Get all objects with timestamp between 1am and 8am for every day that is either a saturday or a sunday.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:32:32+00:00Added an answer on June 7, 2026 at 11:32 pm

    NOT TESTED

    For the first case, assuming MyModel and your timestamp is called date you can do:

    import datetime
    
    start_date = datetime.date(2012,7,1)
    end_date = datetime.date(2012,7,16)
    start_time = datetime.time(14,0)
    end_time = datetime.time(19,0)
    date_range = end_date - start_date
    
    range_list = None
    for days in xrange(date_range.days):
        d = start_date + datetime.timedelta(days)
        if range_list is None:
            range_list = Q(date__range = (datetime.datetime.combine(d, start_time), datetime.datetime.combine(d, end_time)))
        else:
            range_list = range_list|Q(date__range = (datetime.datetime.combine(d, start_time), datetime.datetime.combine(d, end_time)))
    
    
    MyModel.objects.filter(range_list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set a form's ForeignKey field's queryset so that it will
Is it possible to combine a Django Haystack search with built-in QuerySet filter operations,
Is it possible to change some specific items in a QuerySet object? In my
I have for two similar models with one common Manager, that returns queryset for
Is it possible to filter a Django queryset by model property? i have a
I know that you can get the SQL of a given QuerySet using print
Wondering if it's possible to change a value returned from a queryset before sending
Is it possible to LEFT JOIN one QuerySet to another? I know it's possible
Possible Duplicate: django - ordering queryset by a calculated field How can i use
Is it possible to use the django ORM to order a queryset by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.