[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Calculate last day of month

Gavin Kistner

9/21/2006 7:03:00 PM

> How do I return the date for the last day of this month (September in
> this example)?

The last day in a month is the day before the first day in the next
month.

require 'date'
d = Date.new( 2006, 10, 1 )
puts d-1
#=> 2006-09-30

1 Answer

Norgg

9/21/2006 7:57:00 PM

0

Gavin Kistner wrote:
>> How do I return the date for the last day of this month (September in
>> this example)?
>
> The last day in a month is the day before the first day in the next
> month.
>
> require 'date'
> d = Date.new( 2006, 10, 1 )
> puts d-1
> #=> 2006-09-30
>

Slightly nicer is:
puts Date.new(2006, 9, -1)
#2006-09-30