[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Get Previous month

Pragash Mr.

8/6/2008 8:30:00 AM

Hi,
I want previous month name

for example
Time.now.strftime("%B")
will result the month name "August"

But i need to find the previous month if anybody knows reply me.....
--
Posted via http://www.ruby-....

2 Answers

Shadowfirebird

8/6/2008 8:53:00 AM

0

Hi,

thistimelastmonth = Date.today << 1
lastmonth = thistimelastmonth.month
answer = Date::MONTHNAMES[month]

I wouldn't recommend that you use those variable names, but hopefully
you get the idea.


On Wed, Aug 6, 2008 at 9:30 AM, Pragash Mr.
<gananapragasam@srishtisoft.com> wrote:
> Hi,
> I want previous month name
>
> for example
> Time.now.strftime("%B")
> will result the month name "August"
>
> But i need to find the previous month if anybody knows reply me.....
> --
> Posted via http://www.ruby-....
>
>



--
All you can do is try to know who your friends are as you head off to
the war / Pick a star on the dark horizon and follow the light

Marc Heiler

8/6/2008 11:31:00 AM

0

Shadowfirebird wrote:
> Hi,
>
> thistimelastmonth = Date.today << 1
> lastmonth = thistimelastmonth.month
> answer = Date::MONTHNAMES[month]
>
> I wouldn't recommend that you use those variable names, but hopefully
> you get the idea.
>
>
> On Wed, Aug 6, 2008 at 9:30 AM, Pragash Mr.


Your example looks cool :)

I took the liberty to change it to a one liner.

Date::MONTHNAMES[(Date.today << 1).month] # => "July"
--
Posted via http://www.ruby-....