5

i´m trying to convert a date to mysql format date but is not working.

@complain.date = Date.today.to_s(:db)

Also, i want to save it as datetime format. Any suggests??

2
  • Aren't you using date fields when you create your migrations, in which case rails will do it for you. Commented Apr 6, 2011 at 20:34
  • 4
    Time.now.to_s(:db) or Time.now.strftime("%Y-%m-%d %H:%M:%S") Commented Apr 6, 2011 at 20:39

1 Answer 1

10

You don't need to convert manually; just do:

@complain.date = Date.today
Sign up to request clarification or add additional context in comments.

2 Comments

Remember that this only returns the Date. If you have a column of DATETIME type, you should use Time.now.to_s(:db)
the :db is no joke!

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.