ruby on rails - Sum date object and time object on RoR -
sorry english...
i have 2 object, 1 date object , 1 time object, want sum them datetime object, trying...
[35] pry(main)> dateobj = date.today => sun, 06 oct 2013 [36] pry(main)> timeobj = time.parse("02:00:00") => 2013-10-06 02:00:00 -0600 [37] pry(main)> datetimeobj = dateobj + timeobj typeerror: expected numeric /home/elquick/www/rails/vivsan/http/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.14/lib/active_support/core_ext/date/calculations.rb:90:in `+' [38] pry(main)>
some help?
thanks!
try use
date.today.to_datetime + time.parse('02:00:00').seconds_since_midnight.seconds
here result:
.0.0-p195 :019 > date.today.to_datetime => mon, 07 oct 2013 00:00:00 +0000 2.0.0-p195 :020 > time.parse('02:00:00').seconds_since_midnight.seconds => 7200.0 seconds 2.0.0-p195 :021 > date.today.to_datetime + time.parse('02:00:00').seconds_since_midnight.seconds => mon, 07 oct 2013 02:00:00 +0000
Comments
Post a Comment