# \[newbie\] This Month / Next Month / The One After That

**URL:** <https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813>\
**Category:** Rails\
**Created:** [January 16, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813 "2006-01-16T20:53:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 16, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/1 "2006-01-16T20:53:51Z")

</div>

What I want to do is simple.

I’d like code that prints out the name of this month (January) the next  
month (February) and the one after that (March)

I’ve been able to print this month:

\<% t = Time.now %\>  
\<%= t.strftime(" This Month is: %B") %\>

But I can’t figure out how to get the next months to print out!

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 17, 2006, 1:03am UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/2 "2006-01-17T01:03:30Z")

</div>

On 16 Jan '06, at 11:53 AM, Mason K. wrote:

> I’d like code that prints out the name of this month (January) the  
> next  
> month (February) and the one after that (March)

I was delving into the time/date morass over the weekend\*, so now I  
get to sound like an expert:

Date.today.mon returns the current month number (1…12).  
Date::MONTHNAMES is an array of month names.

Don’t forget to use modular arthmetic, of course 🙂

\*And may I take a moment to gripe about how confusing it is that Ruby  
has entirely distinct Time and Date classes, and that there is no  
obvious way to convert between them? I spent about an hour on  
Saturday trying to find a way to compute the number of days between  
two Times.

–Jens

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 17, 2006, 1:12am UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/3 "2006-01-17T01:12:37Z")

</div>

2006/1/16, Jens A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> \*And may I take a moment to gripe about how confusing it is that Ruby has  
> entirely distinct Time and Date classes, and that there is no obvious way to  
> convert between them? I spent about an hour on Saturday trying to find a way  
> to compute the number of days between two Times.

Look no further than ActiveSupport:

Date#to\_time # returns self, converted to a Time @ midnight  
Date#to\_date # returns self  
Time#to\_date # returns self, converted to a Date  
Time#to\_time # returns self

Hope that helps !

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 17, 2006, 1:15am UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/4 "2006-01-17T01:15:21Z")

</div>

Thanks.

I’ve only been at this for a few weeks in my spare time so this will  
save me much headache.

I really appreciate your help!

mk

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 23, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/5 "2006-01-23T16:37:19Z")

</div>

But how to change month names ? to obtain french month for instance…

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 23, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/6 "2006-01-23T17:41:00Z")

</div>

thank you for your help.

> > But how to change month names ? to obtain french month for instance…
> 
> Just use your own array instead of Date::MONTHNAMES.
> 
> FRENCH\_MONTHNAMES = [‘Janvier’, ‘Fevrier’, … , ‘Decembre’]

I can use FRENCH\_MONTHNAMES like a table…  
but I want to replace %B in the expression… and i can’t =(

thanks 😉

pm

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 23, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/7 "2006-01-23T17:02:58Z")

</div>

pm wrote:

> But how to change month names ? to obtain french month for instance…

Just use your own array instead of Date::MONTHNAMES.

FRENCH\_MONTHNAMES = [‘Janvier’, ‘Fevrier’, … , ‘Decembre’]

> I was delving into the time/date morass over the weekend\*, so now I  
> get to sound like an expert:  
> Date.today.mon returns the current month number (1…12).  
> Date::MONTHNAMES is an array of month names.  
> Don’t forget to use modular arthmetic, of course 🙂

next = 1.month.from\_now  
nextnext = 2.months.from\_now

\<%= next.strftime(" Next Month is: %B") %\>  
\<%= nextnext.strftime(" The Month After That One is: %B") %\>

🙂

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 23, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/8 "2006-01-23T18:29:20Z")

</div>

pm wrote:

> thank you for your help.
> 
> > > But how to change month names ? to obtain french month for instance…
> > 
> > Just use your own array instead of Date::MONTHNAMES.
> > 
> > FRENCH\_MONTHNAMES = [‘Janvier’, ‘Fevrier’, … , ‘Decembre’]
> 
> I can use FRENCH\_MONTHNAMES like a table…  
> but I want to replace %B in the expression… and i can’t =(
> 
> thanks 😉
> 
> pm

irb(main):001:0\> Date::MONTHNAMES  
=\> [nil, “January”, “February”, “March”, “April”, “May”, “June”, “July”,  
“August  
“, “September”, “October”, “November”, “December”]  
irb(main):002:0\> Date::MONTHNAMES[1] = ‘Janvier’  
=\> “Janvier”  
irb(main):003:0\> Date::MONTHNAMES[1]  
=\> “Janvier”  
irb(main):004:0\> Time.now  
=\> Mon Jan 23 18:27:28 West-Europa (standaardtijd) 2006  
irb(main):005:0\> Time.now.strftime(”%B”)  
=\> “January”  
irb(main):006:0\> ☹  
irb(main):007:1\*

---

<div class="post-metadata">

**Author:** ![masonkessinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4da419/32.png) [@masonkessinger](https://www.ruby-forum.com/u/masonkessinger)\
**Post date:** [January 24, 2006, 11:06am UTC](https://www.ruby-forum.com/t/newbie-this-month-next-month-the-one-after-that/61813/9 "2006-01-24T11:06:44Z")

</div>

“And finally, everything worked out just fine.  
Christmas was saved, though there wasn’t much time.  
But after that night, things were never the same”  
Danny Elfman =)

I have found the solution… I have override strftime with this code =)  
And it’s so great =)

[http://poocs.net/articles/2005/10/04/localization-for-rubys-time-strftime](http://poocs.net/articles/2005/10/04/localization-for-rubys-time-strftime)

Thanks a lot
