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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5fc51cc8-bef1-4df6-8b6b-1fc388abe75e%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Jul-19 13:29 UTC
Re: Normalize dates taht are entered in more then one way.
On 18 July 2013 15:35, Mark Kenney <markkenney22-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.Where are the dates coming from? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLunoai0WfE9%2BZQj6bfwNdOVJCO14jAP1guXg-ZTCw%2BEcg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Andrew Vit
2013-Jul-20 01:43 UTC
Re: Normalize dates taht are entered in more then one way.
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
On Thursday, July 18, 2013 7:35:46 AM UTC-7, Mark Kenney
wrote:>
> 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
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/b0d35166-350d-44b1-aa9e-320ce3e97577%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Seemingly Similar Threads
- How to run rsync as a daemon program taht runs at particular time given
- Help in understanding physreg LiveVariables
- Adding BB input/output registers during ISel
- Probit Analysis: Confidence Interval for the LD50 using Fieller's and Heterogeneity (UNCLASSIFIED)
- Help in understanding physreg LiveVariables