How to update date field?

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 ,for example: 2006-09-30 11:37:25,then how to update the
field “created” after the request is submited?

On 9/28/06, Benson [email protected] 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 ,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…

Daniel ----- wrote:

On 9/28/06, Benson [email protected] 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 ,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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs