Hello, I have a parse that reads in a file and populates my database. The problem is that when I use Time.parse it interprets the second digit as the month rather than the day. For example: Input: 12-04-2007 21:15:56 Shows as Apr 12, 2007 Controller Line: wanted.earlist_pre_order = Time.parse(items[12]) Any help would be greatly appreciated. Barb -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Barb Wood wrote:> Hello, > > I have a parse that reads in a file and populates my database. The > problem is that when I use Time.parse it interprets the second digit as > the month rather than the day. > > For example: > Input: 12-04-2007 21:15:56 > Shows as Apr 12, 2007 > > Controller Line: wanted.earlist_pre_order = Time.parse(items[12]) > > Any help would be greatly appreciated. > > BarbWell that''s not an error. It depends on where you live. I think you can try somewhere the strftime method -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 28, 2007 10:34 PM, Barb Wood <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello, > > I have a parse that reads in a file and populates my database. The > problem is that when I use Time.parse it interprets the second digit as > the month rather than the day. > > For example: > Input: 12-04-2007 21:15:56 > Shows as Apr 12, 2007 > > Controller Line: wanted.earlist_pre_order = Time.parse(items[12]) > > Any help would be greatly appreciated.Date/Time.parse uses a variety of heuristics in an attempt to deal with the various ways we present dates around the world. I think that using "-" for the separator triggers it to interpret the date in EU format dd-mm-yyyy and a ''/'' causes it to use the US interpretation mm/dd/yyyy -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/28/07, Barb Wood <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a parse that reads in a file and populates my database. The > problem is that when I use Time.parse it interprets the second digit as > the month rather than the day. > > For example: > Input: 12-04-2007 21:15:56 > Shows as Apr 12, 2007 > > Controller Line: wanted.earlist_pre_order = Time.parse(items[12]) > > Any help would be greatly appreciated.You can use strptime to parse dates/times with unusual formats: http://www.ruby-doc.org/core/classes/DateTime.html#M002824 -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---