DATE_FORMAT error in ruby in rails 4 with sql serv

2019-09-14 18:08发布

问题:

i am getting DATE_FORMAT error in ruby on rails with sql server as a database

<% date = Date.today %>
<% @employees = Employee.where("status = ? AND DATE_FORMAT(date_of_birth,'%d/%m') = ?", "Active" , date.strftime('%d/%m')) %>

回答1:

Try this,

<% date = Date.today %>
<% @employees = Employee.where("status = ? AND FORMAT(date_of_birth,'dd/MM','en-US') = ?", "Active" , date.strftime('%d/%m')) %>

Learn more about Format function