Jmohey
Jmohey

Reputation: 163

Rails where statement with datetime.month

I am trying to find the data points within a database (PG) whose date is within a certain month (and would also quite like to check the year is the same also)

I have tried:

my_data.where("date.month = ?", month )

where 'month' is an integer (eg from Time.new.month) but doesn't seem to work...

Upvotes: 2

Views: 2208

Answers (1)

Hieu Pham
Hieu Pham

Reputation: 6707

So the query will be like this:

my_data.where("EXTRACT(MONTH FROM date) = ?", month)

Upvotes: 5

Related Questions