[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Creating a future date

aidy

6/5/2006 5:27:00 PM

Hi,

I am trying to get a date a year from today. I have got this which
gives me a day in advance

t = Time.now;t1 = t + 100000
p end_date = t1.localtime.strftime("%d/%m/%Y")


I have looked in 'The Ruby Way' and it provides a 'Converting Between
Seconds and Larger Units' method.

Surely there must be a better way?

Aidy

3 Answers

coachhilton

6/5/2006 6:58:00 PM

0


How about this:
irb(main):001:0> t = Time.now
=> Mon Jun 05 11:57:01 PDT 2006
irb(main):002:0> t.year
=> 2006
irb(main):003:0> t.month
=> 6
irb(main):004:0> t.day
=> 5
irb(main):005:0> t = Time.local(t.year+1, t.month, t.day)
=> Tue Jun 05 00:00:00 PDT 2007

Ken

aidy wrote:
> Hi,
>
> I am trying to get a date a year from today. I have got this which
> gives me a day in advance
>
> t = Time.now;t1 = t + 100000
> p end_date = t1.localtime.strftime("%d/%m/%Y")
>
>
> I have looked in 'The Ruby Way' and it provides a 'Converting Between
> Seconds and Larger Units' method.
>
> Surely there must be a better way?
>
> Aidy

JimC

6/5/2006 7:34:00 PM

0

How about this:

d = Date::today >> 12
p d.to_s

------------------------------------------------------- Date#>>
>>(n)
---------------------------------------------------------------
Return a new Date object that is n months later than the current one.

If the day-of-the-month of the current Date is greater than the last
day of the target month, the day-of-the-month of the returned Date will
be the last day of the target month.

HTH,
Jim

Martin Nemzow

6/7/2006 9:59:00 PM

0

That is a cool solution!

"JimC" <jim.coutu@gmail.com> wrote in message
news:1149536010.612947.8710@g10g2000cwb.googlegroups.com...
> How about this:
>
> d = Date::today >> 12
> p d.to_s
>
> ------------------------------------------------------- Date#>>
> >>(n)
> ---------------------------------------------------------------
> Return a new Date object that is n months later than the current one.
>
> If the day-of-the-month of the current Date is greater than the last
> day of the target month, the day-of-the-month of the returned Date will
> be the last day of the target month.
>
> HTH,
> Jim
>