How do we explode a string on ‘-‘ and again implode it on ‘-‘ in ruby on rails.My problem is that i want to convert a date in "MM-DD-YYYY" format to 'YYYY-MM-DD' coming from a form and save it to mysql database.As MySQL will only accept 'YYYY-MM-DD' format.
How do we explode a string on ‘-‘ and again implode it on ‘-‘
Share
Rails do not support MM-DD-YYYY out of the box. It’s often impossible to differ them from DD-MM-YYYY and that could be why.
You can use Date::strptime
You do not actually have to format it as YYYY-MM-DD because ActiveRecord just needs a date object.