0

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:               <% date = Date.today %>
    212:              <% @employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')) %>
    213:             <% if @employees.empty? %>
    214:              
    215:             <%else%>
    216:               <% @employees.each do |e| %>
  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')

2 Answers 2

1

Try this with simply replace,

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

With

<% @employees = Employee.where("status = ? AND DATE_FORMAT(date_of_birth,'%d/%m') = ?", "Active" , date.strftime('%d/%m')) %>
Sign up to request clarification or add additional context in comments.

16 Comments

i am getting this error on windows when i am running my project and doing rake db:migrate
D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require': Could no t load 'active_record/connection_adapters/mysql2_adapter'. Make sure that the adapter in config/database.yml is valid. I f you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfil e. (LoadError)
Everthing works fine on Linux ubuntu,only on windows i am getting this error.
you need to install mysql in windows machine..as well
i am having problem while exporting my datababase in mysql, i have alo ran mysqldump -h [host] -u [uname] -p[pass] db_name > db_backup.sql then database.sql,and also source database.sql still no data in tables??????
|
0

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

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

4 Comments

Will you please provide me an example of how may i apply DATE_FORMAT in rails 4.I am new to this so don't know.
date = Date.today @employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m'))
i want to convert this query to mysql.
my new question.............stackoverflow.com/questions/43065691/… @hardik

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.