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 7710283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:05:18+00:00 2026-06-01T01:05:18+00:00

I have a Django model with separate Datefield and Timefield for an event. Is

  • 0

I have a Django model with separate Datefield and Timefield for an event. Is there a way to convert it to a python datetime object so I can query for the upcoming events with some precision? Currently I get only the upcoming of the following day.

models.py

event_time = models.TimeField()
event_date = models.DateField()

Basically, can I filter with a minute, or even split second precition?

Thank you.

  • 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-01T01:05:20+00:00Added an answer on June 1, 2026 at 1:05 am

    Use a DateTimeField instead (see this section in the docs). Conversion to a datetime.datetime is handled for you by Django automatically.

    A DateField results in a datetime.date and a datetime.time object. You can use replace to merge these values into an updated date:

    >>> today = datetime.datetime.today()
    >>> today
    datetime.datetime(2012, 3, 31, 11, 6, 5, 182371)
    >>> time = datetime.time(11, 30)
    >>> today.replace(hour=time.hour, minute=time.minute)
    datetime.datetime(2012, 3, 31, 11, 30, 5, 182371)
    

    Note that the resulting date has 11.30 as time now. Note also that today is not modified, it simply computes a new date and time. As you can see, you now have to do the merging yourself because both values are stored in separate fields. That’s why a DateTimeField is a much better choice, if you have the ability to modify the model’s fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django model TimeThingie with two TimeField s called t1 and t2
I have a failing model.save() in my Django app. How can I see the
Is there a way in Django to add custom attributes to a model's fields
I have a Django model with a large number of fields and 20000+ table
I want to generate a list using my django model say I have these
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have a django app with models as follows: A Question model An Answer
I have a Django form that uses an integer field to lookup a model
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)

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.