Reputation: 81
I want to create a query for fetching records from database. In Manager Model, Manager Table has date_of_birth column. Query is:
Manager.all.where(:date_of_birth => Date.now)
Through Query whole format of date_of_birth column compare to current date in Manager Controller's Index action.But my requirement is to compare month and day of date_of_birth column to today's day and month.How can I do that? Please help me. Thanks in advance.
Upvotes: 1
Views: 127
Reputation: 1500
You can use the SQL methods MONTH()
and DAY()
for your query like this :
Manager.all
.where("MONTH(date_of_birth) = (?)", Date.now.month)
.where("DAY(date_of_birth) = (?)", Date.now.day)
Documentation :
Upvotes: 1