nuno wrote:> Hello,
>
> (Time.now + 1.year).to_s(:db) works fine => "2007-08-24
20:56:38"
> (Date.today + 1.year).to_s(:db) produce wrong result =>
"88408-06-02"
In Ruby, Date and Time are different types. The + operator for Time
will add seconds. The + operator for Date adds days.
The 1.year is basically just a multiplier of seconds. So, if for some
reason you want to use Date instead of Time, you should convert it to
Time before adding:
>> (Date.today.to_time + 1.year).to_s(:db)
=> "2007-08-24 06:00:00"
--
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
-~----------~----~----~----~------~----~------~--~---