-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)):
4
  • Does this help? Commented Apr 5, 2017 at 9:21
  • Can you please add what os object is? Commented Apr 5, 2017 at 9:22
  • @anu jainThere is no strftime function in MySQL. Use DATE_FORMAT instead. Commented Apr 5, 2017 at 9:25
  • @Dnyanarthlonkar DATE_FORMAT is not working on index page . Commented Apr 5, 2017 at 9:28

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

can you show me the result of os.ot_daily_date.class?
0

Try this:

<% year = os.ot_daily_date.to_date.year %>

2 Comments

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.
Now the answer lacks explanation. What do you think the problem is, and why this code should help?

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.