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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:40:05+00:00 2026-06-06T02:40:05+00:00

I have a mongo database where I’m storing a date and time in separate

  • 0

I have a mongo database where I’m storing a date and time in separate fields (I do not have the ability to change this setup). Googling around, I found examples of people querying dates and times by breaking fields up into 2 parts, 1 for date and 1 for time, like:

{"dateField": {"d": "06/18/2012" "t": "12:00:00 AM"}}
{"timeField": {"d": "06/18/2012" "t": "12:07:10 PM"}}

I’ve seen people (and have been able to myself) query the date portion:

db.collection.find({"dateField.d": {"$gte": "06/18/2012"}})

My problem is I cannot get accurate results trying the same thing with time:

db.collection.find({"timeField.t": {"$gte": "12:00:00 PM"}})

Is there a specific way I should be formatting my time data to query it? Or is there a better way for storing time data so that I can query just the time (without it being dependent on a date)?

  • 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-06T02:40:06+00:00Added an answer on June 6, 2026 at 2:40 am

    You need to store data in a real Date format or as numbers. When you are doing those searches the comparison is using lexicography order which is not what you want. If you do want to use strings you should use one of the ISO formats where it works.

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

Sidebar

Related Questions

I have many collections of documents in a mongo database that look like this:
I have a database connection that I got like this: db = Mongo::Connection.new.db(app-development) but
I have this line: @users = database['users'].find(:all).limit(10) it returns this object: <Mongo::Cursor:0x8759a858 namespace='app-development.users' @selector=:all
I have to read an existing mongo database. Is mongoid suitable for this? All
I have a subobject in a mongo database with fields that contain spaces, something
I have an existing mongo database where all documents in a collection have a
I have mongo documents in this format. {_id : 1,Summary : {...},Examples : [{_id
I have a mongo collection which has documents with two fields fieldA and fieldB,
I have been adding files to GridFS in my 32bit Mongo database. It eventually
No idea why this is not working. It's the first time I am working

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.