postgresql - How do you filter records by the time of day in Rails? -
i have bunch of records have datetime
stored on them used pull out time of day (i.e. 6:00 p.m.) , i'd filter them time of day. example, i'd records time of day between 10:00 a.m. , 2:00 p.m., regardless of day timestamp for.
is there way in rails? realize datetime
might not easiest/best way store data, i'm open changing that. also, i'm using postgres.
with postgres can use typecasting convert datetime/timestamp fields time, example:
select * posts created_at::time between '10:00:00' , '14:00:00';
so, in rails, should able do:
post.where('start_at::time between ? , ?', '10:00:00', '14:00:00')
and postgres smart enough understand am/pm format also:
post.where('start_at::time between ? , ?', '10:00:00 am', '02:00:00 pm')
Comments
Post a Comment