0

I have some data like

id   post  created_at
1     test  timestamp 
2     hello  timestamp 
3     test  timestamp 

  • how can return data for specific date for example 2020-06-14
  • how can return data for specific hour from specific date 2020-06-14 11

i use rails, postgres

1 Answer 1

1

Try the following:

Post.where("date(created_at) = ?", Date.parse('2020-06-14'))

and

Post.where("date_trunc('hour', created_at) = ?", Time.parse('2020-06-14 11:00'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.