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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:44:20+00:00 2026-05-21T20:44:20+00:00

@events = Event.all(:order => date DESC) to order my events by date, a datetime

  • 0
@events = Event.all(:order => "date DESC")

to order my events by date, a datetime column.

Is it possible to order them not by date, but only by hour? (I’m suing sqlite3 database)

Thanks!

  • 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-05-21T20:44:21+00:00Added an answer on May 21, 2026 at 8:44 pm

    For SQLite,

    @events = Event.all(:order => "time(date) DESC")
    

    Use that with care, because it ignores the date. (And see “Moments later” below.)

    CREATE TABLE test (date datetime primary key);
    INSERT INTO "test" VALUES('2011-01-01 08:00:00');
    INSERT INTO "test" VALUES('2011-01-01 08:13:00');
    INSERT INTO "test" VALUES('2011-01-01 09:23:00');
    INSERT INTO "test" VALUES('2011-01-02 09:15:00');
    

    Only one of the dates is on Jan 2.

    sqlite> select * from test order by time(date) desc;
    2011-01-01 09:23:00
    2011-01-02 09:15:00
    2011-01-01 08:13:00
    2011-01-01 08:00:00
    

    Moments later . . .

    I realized you wanted to sort by hour, not by time. That questionable requirement takes a different expression, and sorts differently.

    @events = Event.all(:order => "strftime('%H', date) DESC")
    
    sqlite> select date from test order by strftime('%H', date) desc;
    2011-01-01 09:23:00
    2011-01-02 09:15:00
    2011-01-01 08:00:00
    2011-01-01 08:13:00
    

    The last two rows are sorted correctly by hour, incorrectly by time.

    Still later . . .

    The OP deploys on Heroku, which doesn’t support SQLite. To sort by hour descending, the OP probably needs something like

    @events = Event.all(:order => "extract (hour from date) DESC")
    

    And stop using one platform for development and a different platform for deployment.

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

Sidebar

Related Questions

What if I want not only to add events for all future added, but
This question doesn't relate only to MouseEvent.CLICK event type but to all event types
I want to know when all of the events for a mouse event have
What I would like to find is all Events, where event.event_date is in the
I have an Events table with a not-null date field. Based on a pivot
I have defined an Event class: Event and all the following classes inherit from
I know that the live() event handles event bubbling different than all other jQuery
I will use (again) the following class hierarchy: Event and all the following classes
In Ruby, I'm trying to do the following. def self.stats(since) return Events.find(:all, :select =>
I have 2 event handlers: Y.all(.ptl).on(mouseover, handleOverlay); Y.all(.ptl).on(mouseout, handleOverlay); And I would like to

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.