Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How to compare and write conditions on active record field "time"

General • Asked by sid d
 Fpclass(id: integer, name: string,  start_time: time)

 # 2000-01-01 01:01:00 UTC

I'm having problem with comparing time field while fetching results as you've seen above its storing all date and time in database even though i mentioned Time field while creating. Does anyone had faced similar kind of problem before ? Can you share me how to approach with time fields in active record, or am i doing something wrong ?

Finally what i need ?

 Fpclass.where('start_time>?',"%H %M"))


So all the Time instances in Rails include a date with the Time. It will default to January 1st, 2000 as you can see but you can safely ignore that portion of the output.

You should be able to query the database just by doing this and it should ignore the Date portion of the time. Check the development logs for the SQL query to make sure it does.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.