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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:28:40+00:00 2026-06-16T13:28:40+00:00

I’m using MongoDB and Mongoid in my project. I have some difficulties with ordering

  • 0

I’m using MongoDB and Mongoid in my project. I have some difficulties with ordering “Time” field data.

As you know, eventhough you set a field type as Time inside your Mongoid Document, time data is stored as this format (note that I use +2 hours offset to get my own timezone’s time instead of UTC):

Mon, 31 Dec 2012 08:30:00 EET +02:00

I’m not sure if I’m missing something but this is what happens to me.

I want to use that Time data inside one of my views. I need to sort some related stuff by ONLY Hour:Minute format. I don’t want Rails to take care of the DATE part of the field data. Because whenever a new Time record inserted to DB, it takes the day info as CURRENT DAY.

Issue is:

Because of it saves CURRENT DAY for each of new Time records, when I try to order_by("hour DESC") NEW records always retrieved first eventhough HOUR part of the data is bigger!

For example:

First data:
=> Tue, 27 Nov 2012 19:50:00 EET +02:00
Second data:
=> Mon, 24 Dec 2012 18:45:00 EET +02:00

As you know, normally, 19:50 is bigger than 18:45. But in this scenario, because of Rails takes day info into calculation, 18:45 looks like bigger than 19:50!

So what is the work around for this issue?

Thanks in advence.

  • 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-16T13:28:41+00:00Added an answer on June 16, 2026 at 1:28 pm

    I’ve found an answer to this at Mongoid’s issues list:
    https://github.com/mongoid/mongoid/issues/1169

    That’s really weired…

    If I understood well, Time field type is totally useless! What is the difference between DateTime and Time then??

    You even can not compare hours and minutes ONLY inside a Time field.

    And hold your breath for the work around…

    Solution is:

    Not to use Time field type! Just use String and compare hours and dates via that procedure.

    Person.where(:time.gt => "13:00")
    

    If some could explain this weired situation, I would be happy.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have thousands of HTML files to process using Groovy/Java and I need to
I am using jsonparser to parse data and images obtained from json response. When
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.