I just don''t understand this and leap years make this problem obvious to me...>> test = DateTime.now=> #<DateTime: 53017684949923739/21600000000,-7/24,2299161>>> test.strftime("%Y-%m-%d")=> "2008-02-25">> test = DateTime.now + 365=> #<DateTime: 70700758603797619/28800000000,-7/24,2299161>>> test.strftime("%Y-%m-%d")=> "2009-02-24" seems reasonable, off a day because of leap year...>> test = DateTime.now + 1.year=> #<DateTime: 1469323689922559749/43200000000,-7/24,2299161>>> test.strftime("%Y-%m-%d")=> "88409-12-04" how do I add a simple year? Craig --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White wrote:> how do I add a simple year? > > CraigI did DateTime.now.year will give 2008. DateTime.now.year + 1 give 2009 -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 25 Feb 2008, at 23:52, Craig White wrote:> I just don''t understand this and leap years make this problem > obvious to > me... > >>> test = DateTime.now > => #<DateTime: 53017684949923739/21600000000,-7/24,2299161> >>> test.strftime("%Y-%m-%d") > => "2008-02-25" > >>> test = DateTime.now + 365 > => #<DateTime: 70700758603797619/28800000000,-7/24,2299161> >>> test.strftime("%Y-%m-%d") > => "2009-02-24" > > seems reasonable, off a day because of leap year... > >>> test = DateTime.now + 1.year > => #<DateTime: 1469323689922559749/43200000000,-7/24,2299161> >>> test.strftime("%Y-%m-%d") > => "88409-12-04" > > how do I add a simple year?Time.now.next_year Don''t use DateTime. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, 2008-02-26 at 00:03 +0100, Peter De Berdt wrote:> > On 25 Feb 2008, at 23:52, Craig White wrote: > > > I just don''t understand this and leap years make this problem > > obvious to > > > > me... > > > > > > > > test = DateTime.now > > > > > > > > => #<DateTime: 53017684949923739/21600000000,-7/24,2299161> > > > > > > test.strftime("%Y-%m-%d") > > > > > > > > => "2008-02-25" > > > > > > > > test = DateTime.now + 365 > > > > > > > > => #<DateTime: 70700758603797619/28800000000,-7/24,2299161> > > > > > > test.strftime("%Y-%m-%d") > > > > > > > > => "2009-02-24" > > > > > > seems reasonable, off a day because of leap year... > > > > > > > > test = DateTime.now + 1.year > > > > > > > > => #<DateTime: 1469323689922559749/43200000000,-7/24,2299161> > > > > > > test.strftime("%Y-%m-%d") > > > > > > > > => "88409-12-04" > > > > > > how do I add a simple year? > > > > Time.now.next_year > > > Don''t use DateTime.---- gotcha... this is really painful, test = ((DateTime.now.year + 1).to_s + "-" + DateTime.now.month.to_s + "-" + DateTime.now.day.to_s).to_date but I do need dates so I have to convert back to a date but thankfully, that isn''t so hard to do. Thanks Craig --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 25, 2008, at 4:52 PM, Craig White wrote:> > I just don''t understand this and leap years make this problem > obvious to > me... > >>> test = DateTime.now > => #<DateTime: 53017684949923739/21600000000,-7/24,2299161> >>> test.strftime("%Y-%m-%d") > => "2008-02-25" > >>> test = DateTime.now + 365 > => #<DateTime: 70700758603797619/28800000000,-7/24,2299161> >>> test.strftime("%Y-%m-%d") > => "2009-02-24" > > seems reasonable, off a day because of leap year... > >>> test = DateTime.now + 1.year > => #<DateTime: 1469323689922559749/43200000000,-7/24,2299161> >>> test.strftime("%Y-%m-%d") > => "88409-12-04" > > how do I add a simple year? > > Craig >Hi Craig, You might find this interesting: http://railscasts.com/episodes/54 Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 25, 2008, at 6:03 PM, Peter De Berdt wrote:> On 25 Feb 2008, at 23:52, Craig White wrote: >> I just don''t understand this and leap years make this problem >> obvious to >> me... >> >>>> test = DateTime.now >> => #<DateTime: 53017684949923739/21600000000,-7/24,2299161> >>>> test.strftime("%Y-%m-%d") >> => "2008-02-25" >> >>>> test = DateTime.now + 365 >> => #<DateTime: 70700758603797619/28800000000,-7/24,2299161> >>>> test.strftime("%Y-%m-%d") >> => "2009-02-24" >> >> seems reasonable, off a day because of leap year... >> >>>> test = DateTime.now + 1.year >> => #<DateTime: 1469323689922559749/43200000000,-7/24,2299161> >>>> test.strftime("%Y-%m-%d") >> => "88409-12-04" >> >> how do I add a simple year? > > Time.now.next_year > > Don''t use DateTime. > > Best regards > > Peter De BerdtWell, since DateTime < Date, you can test >>= 12 to advance test by 12 months. (and if you try in 4 days (on 2008-02-29), the result will be 2009-02-28 ;-) But you probably want either a Date or a Time anyway. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---