Forum: Ruby on Rails Normalize dates taht are entered in more then one way.

B2269cb9ff1e328a26de680b31625efb?d=identicon&s=25 Mark Kenney (Guest)
on 2013-07-19 13:17
(Received via mailing list)
Hi all,

I'm looking for a function, gem, etc. that will help to unify dates as
they
come in different formats. If the date comes in
(1/2/2012,2012-01-02,01-02-2012,20120102,01022012, etc.) it would be
nice
to have it come out 2012-01-02. I've searched for a few days and only
find
ways to convert this format to that format. I might be using the wrong
search terms and this may have already been addressed, if so, I
apologize.
In my previous PERL app I wrote a long If Else type converter that would
test the date and then convert it in a specific order but I'm sure
someone
has solved it better then I could.

Any help would be greatly appreciated!!!

Mark
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2013-07-19 15:31
(Received via mailing list)
On 18 July 2013 15:35, Mark Kenney <markkenney22@gmail.com> wrote:
> it better then I could.
Where are the dates coming from?

Colin
F0987c97234fa9c6b26f796bdbdab037?d=identicon&s=25 Andrew Vit (Guest)
on 2013-07-20 03:45
(Received via mailing list)
The standard Date class can do parsing for some basic formats:

Date.parse('2000-11-22')
Date.parse('11-22-2000')
Date.parse('1-2-2000')
Date.parse('11/22/2000')
Date.parse('22/11/2000')
Date.parse('20001122')

But you should probably expect input that will be ambiguous. I'm not
sure
how you want to resolve that, unless you give your users "region"
preferences, so they can select the format they prefer to use. (You need
to
know what "1-2-2000" means: can you just decide if it's MDY or DMY?)

Andrew Vit
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.