Date manipulation in rails

J

Johan Allard

Hi all,

I live in australia in in Australia dates are written as DD/MM/YYYY. In
the database, the dates are stored as YYYY-MM-DD. I want to use the
before_validation function and check if #{(\d+)/(\d+)/(\d+)} and then
convert to the correct iso date format.

The problem is that when the before_validation function kicks in, the
date variable is now a Date object. It is no longer a string, and it
has been formatted using the american MM/DD/YYYY format to YYYY-MM-DD.
Since it is a date object, it is not possible to check how the date was
formatted.

Currently I run the check in the controller and to keep the model
intact it would be fantastic if there was a way of doing this in the
before_validation function (or similar) instead.

Thank you

//johan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top