Hi Everybody, I have some issue with date formats. Like I using calender select plugin to select date, It will return the date with US format like "MM-DD-YYYY". If I save this in mysql table, it stores like "YYYY-MM-DD" 12-31-2007 (31st Dec 2007) stored in MYSQL like 2007-31-12 ( Actually NULL cos 12 th day, 31 st month and 2007). Like I cant store the date 12-31-2007 in US format in MYSQL table. Any suggestion appreciated. Regards, T.Veeraa. -- 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 12/14/07, Veera Sundaravel <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Everybody, > > I have some issue with date formats. > > Like I using calender select plugin to select date, It will return the > date with US format like "MM-DD-YYYY". > > > If I save this in mysql table, it stores like "YYYY-MM-DD" > > 12-31-2007 (31st Dec 2007) stored in MYSQL like 2007-31-12 ( Actually > NULL cos 12 th day, 31 st month and 2007). > > Like I cant store the date 12-31-2007 in US format in MYSQL table.Databases store dates in YYYY-MM-DD format so that operations like sorting by date work properly. But why do you care. ActiveRecord will convert to and from ruby Time or DateTime objects and you can format them for display as you wish, no matter how they are stored in the DB. -- 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 -~----------~----~----~----~------~----~------~--~---
felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-14 19:13 UTC
Re: Problem with date format.
Lets try and make this easier for the OP to read... You don''t need to worry how the date is stored in the tables. You are not going to access the tables directly (unless you need another external app interacting with the same database). You are going to access them trough Models. When a model has a method that relates to a date column, it is going to return a Date object. When a model has a method that relates to a datetime column, it is going to return a Time object. So, lets say you have an Order model (that relates to the Orders table) and this Order model has a shipped_at attribute (relates to the shipped_at datetime column in your database). You can store the data on this attribute by using "@order.shipped_at = Time.now". If you need to read this datetime to show to the user in a view, you can use "@order.shipped_at.to_formatted_s(:short)". This will generate something readable. For more help generating different Time objects, use: http://ruby-doc.org/core/classes/Time.html Several examples are shown in AWDWR and on this group. On Dec 14, 10:24 am, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/14/07, Veera Sundaravel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > Hi Everybody, > > > I have some issue with date formats. > > > Like I using calender select plugin to select date, It will return the > > date with US format like "MM-DD-YYYY". > > > If I save this in mysql table, it stores like "YYYY-MM-DD" > > > 12-31-2007 (31st Dec 2007) stored in MYSQL like 2007-31-12 ( Actually > > NULL cos 12 th day, 31 st month and 2007). > > > Like I cant store the date 12-31-2007 in US format in MYSQL table. > > Databases store dates in YYYY-MM-DD format so that operations like > sorting by date work properly. > > But why do you care. ActiveRecord will convert to and from ruby Time > or DateTime objects and you can format them for display as you wish, > no matter how they are stored in the DB. > > -- > Rick DeNatale > > My blog on Rubyhttp://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 -~----------~----~----~----~------~----~------~--~---