I have a text field which is filled with a date from the jQuery UI Datepicker. Depending on the date format the user has selected in their profile on my site, datepicker will either fill in the text field with DD-MM-YYYY or MM-DD-YYYY. If the date is filled in as DD-MM-YYYY, Ruby on Rails interprets this correctly and the date is stored correctly. But when it’s MM-DD-YYYY, Ruby on Rails still thinks that it’s DD-MM-YYYY and so the date is stored incorrectly. How can I change the date format that Rails is expecting?
Share
You can use
Date.strptimeto use any format you want:So the first one is to take the
03as day of month, while the second one is to take it as month.