Suppose the model has a field "created" of Datetime type in mysql, how to update this field using text_field?That means: I type the time in the <input />,for example: 2006-09-30 11:37:25,then how to update the field "created" after the request is submited? -- 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 -~----------~----~----~----~------~----~------~--~---
On 9/28/06, Benson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Suppose the model has a field "created" of Datetime type in mysql, > how to update this field using text_field?That means: I type the time in > the <input />,for example: 2006-09-30 11:37:25,then how to update the > field "created" after the request is submited? > > --If your after a timestamp for when a model is created, just include a created_at column in your table of DateTime. Rails will automatically stamp it when it gets created. Also if your after an update timestamp there is similar functionality from a field updated_at again type DateTime If you want to convert a text input to a date, you could use params[:my_date_field].to_time (or to_date) There is a plugin on www.agilewebdevelopment.com for dates. Maybe you would have some luck with that. http://www.agilewebdevelopment.com/plugins/flex_times Or alternatively there is a project called chronic that may be helpful. Its very early but looks promising http://rubyforge.org/projects/chronic/ Hope that gets you started.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel ----- wrote:> On 9/28/06, Benson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> Suppose the model has a field "created" of Datetime type in mysql, >> how to update this field using text_field?That means: I type the time in >> the <input />,for example: 2006-09-30 11:37:25,then how to update the >> field "created" after the request is submited? >> >> -- > > > If your after a timestamp for when a model is created, just include a > created_at column in your table of DateTime. Rails will automatically > stamp > it when it gets created. > > Also if your after an update timestamp there is similar functionality > from a > field updated_at again type DateTime > > If you want to convert a text input to a date, you could use > params[:my_date_field].to_time (or to_date) > > There is a plugin on www.agilewebdevelopment.com for dates. Maybe you > would > have some luck with that. > > http://www.agilewebdevelopment.com/plugins/flex_times > > Or alternatively there is a project called chronic that may be helpful. > > Its very early but looks promising > > http://rubyforge.org/projects/chronic/ > > Hope that gets you started....Hi Daniel Thanks for your advice,i found another way to update datetime from a text field: require ''parsedate'' str = ParseDate.parsedate("2006-09-30 16:40:32") Time.local(*str) Benson -- 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 -~----------~----~----~----~------~----~------~--~---