Get Previous month

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…

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.

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 :slight_smile:

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

Date::MONTHNAMES[(Date.today << 1).month] # => “July”