Reputation: 3183
I have params[:month,:day,:year]
and I need to convert them into a DateTime
that I can place in a hidden input.
What's the best way to do this in Rails 3?
Upvotes: 37
Views: 36035
Reputation: 5853
You can do
DateTime.new(params[:year], params[:month], params[:day])
Upvotes: 70
Reputation: 303168
Use DateTime.civil
:
require 'date'
date = DateTime.civil( *params.values_at( :year, :month, :day ) )
Upvotes: 12