-1

I used SQLite3 as my database, but now I changed it to MySQL. There is one line in my code which is failing now. What is the syntax for MySQL?

<% year = os.ot_daily_date.strftime("%Y")%>

This line is showing the following error:

ActionView::Template::Error (Mysql2::Error: FUNCTION hrms_development.strftime
does not exist: SELECT `overtime_daily_records`.* FROM `overtime_daily_records`
GROUP BY strftime('%Y',ot_daily_date)):
Christoph Petschnig
  • 4,047
  • 1
  • 37
  • 46
Anu Jain
  • 11
  • 1
  • 6

2 Answers2

0

You can try:

<% year = os.ot_daily_date.year %>

Explain: os.ot_daily_date will return a Date value if ot_daily_date have date data type in your Mysql database.

Hope this helps.

hoangdd
  • 511
  • 2
  • 13
0

Try this:

<% year = os.ot_daily_date.to_date.year %>
Dnyanarth lonkar
  • 869
  • 7
  • 12
  • 1) the supplied error message does not support your hypothesis. 2) rails does __not__ turn everything into strings first time it sees an object. So `os.ot_daily_date` (prior to calling `strftime` on it) would be in no way affected by rails view rendering. – Sergio Tulentsev Apr 05 '17 at 10:03
  • 1
    Now the answer lacks explanation. What do you think the problem is, and why this code should help? – Sergio Tulentsev Apr 05 '17 at 10:06