From: Neil Kohl Date: 2007-09-11T01:45:47+09:00 Subject: Re: Time question ------=_Part_12360_463654.1189442744272 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/10/07, joep wrote: > > I am writing a small piece that will include a date that needs to be > compared to the current time. > > EX. a = Time.now > b = db_cert_date + (72 months) > > if(a < b) > do something > elsif(a > b) > do something else > else > do this > end > > I am looking for the best way to add 72 months onto an old date and > then compare it with the current date. Does anyone have any ideas? > > Thanks in advance > > > How 'bout DateTime? The DateTime#>> operator means "return a new Date object that is n months later than the current one." For your code to work db_cert_date would have to be a DateTime, too. irb(main):018:0> a = DateTime.now => # irb(main):019:0> puts a.strftime('%m/%d/%Y') 09/10/2007 => nil irb(main):020:0> b = a >> 72 => # irb(main):021:0> puts b.strftime('%m/%d/%Y') 09/10/2013 => nil -- Neil Kohl nakohl@gmail.com ------=_Part_12360_463654.1189442744272--