I have a Schedule model with attributes Day and Time. Time is of datatype time.
I have data i.e.
Monday / 2014-04-26 15:00:00.000000
Monday / 2014-04-25 16:30:00.000000
In my controller I have @schedule = Schedule.all(:order => 'Day, Time')
Right now it is ordering by date, how do I order by time regardless of date?
If you're using Postgres you can use
@schedule = Schedule.all.order('date_time_field::time').
If you're on Mysql I think it's something like
DATE_FORMAT(colName,'%H:%i:%s') TIMEONLY
Sqlite
@schedule = Schedule.all.order('time(date_time_field)')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With