Find all data that were created between 9 am and 4pm Rails 3.2.1 and postgreSQL
I have a requirement to display all data that were inserted in between 9 am and 5 pm ignoring dates.
I have tried
*Because Time.parse results in current data and time. So this display only today's result between 9 am and 5 pm.But I need all the data that were entered in between 9am and 5pm *
I tried to solve using time data field in database. Database stores correctly but when we query through rails the year 01-01-2000 was appended in time.
Although it is a very simple problem, I am stuck.
Please help me to figure out this problem.
PostgreSQL defines a function EXTRACT described here: http://www.postgresql.org/docs/current/interactive/functions-datetime.html
You might be able to query using something like the following:
SELECT * FROM (modelname) WHERE EXTRACT(HOUR FROM created_at) > (minhour) AND EXTRACT(HOUR FROM created_at) < (maxhour);