strftime error while switching my database from sqlite3 to mysql in Rails4

匿名 (未验证) 提交于 2019-12-03 01:54:01

问题:

Recently i changed my database from sqlite3 to mysql.When i ran my project i am getting this error in one of the file which is using this query.

date = Date.today + 1

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

ActionView::Template::Error (Mysql2::Error: FUNCTION hrms_development.strftime does not exist: SELECT COUNT(*) FROM `employees` WHERE (status = 'Active' AND strftime('%d/%m', date_of_birth) = '28/03')):     210:                  211:                    212:                   213:                  214:                   215:                  216:                  app/views/home/_group_admin.html.erb:213:in `_app_views_home__group_admin_html_erb___2522183600721478262_91627100'   app/views/home/index.html.erb:17:in `_app_views_home_index_html_erb__2772204906267359422_86967120'    ActionView::Template::Error: Mysql2::Error: FUNCTION hrms_development.strftime does not exist: SELECT COUNT(*) FROM `employees` WHERE (status = 'Active' AND strftime('%d/%m', date_of_birth) = '28/03')

回答1:

Try this with simply replace,

 

With

 


回答2:

There is no strftime function in MySQL. Use DATE_FORMAT instead.

See Convert DateTime Value into String in Mysql for more examples.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!