# Trouble advancing date in iterator

**URL:** <https://www.ruby-forum.com/t/trouble-advancing-date-in-iterator/121441>\
**Category:** Ruby\
**Created:** [November 28, 2007, 12:34am UTC](https://www.ruby-forum.com/t/trouble-advancing-date-in-iterator/121441 "2007-11-28T00:34:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [November 28, 2007, 12:34am UTC](https://www.ruby-forum.com/t/trouble-advancing-date-in-iterator/121441/1 "2007-11-28T00:34:34Z")

</div>

I am trying to assemble an array of month names called  
“names\_of\_months\_paid”:

0 first\_month\_paid = client.first\_month\_paid  
1 names\_of\_months\_paid = []  
2 number\_of\_months\_paid.times do  
3 names\_of\_months\_paid \<\< first\_month\_paid.strftime("%B")  
4 first\_month\_paid \>\> (1)  
5 end

For each payment (“number\_of\_months\_paid”), I need to store the name of  
the month, then store the name of the next month starting from  
“first\_month\_paid”. I seem to be having trouble advancing the month of  
“first\_month\_paid” on line 4 as I am left with an array of first month  
names. How might I get this to work?

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [November 28, 2007, 11:53am UTC](https://www.ruby-forum.com/t/trouble-advancing-date-in-iterator/121441/2 "2007-11-28T11:53:31Z")

</div>

On Nov 28, 2007 12:34 AM, Peter M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## For each payment (“number\_of\_months\_paid”), I need to store the name of the month, then store the name of the next month starting from “first\_month\_paid”. I seem to be having trouble advancing the month of “first\_month\_paid” on line 4 as I am left with an array of first month names. How might I get this to work?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

irb(main):020:0\> t=Time::now  
=\> Wed Nov 28 11:50:38 +0100 2007  
irb(main):021:0\> t.month  
=\> 11  
irb(main):022:0\> Date::MONTHNAMES[t.month]  
=\> “November”  
irb(main):023:0\> m = 12  
=\> 12  
irb(main):024:0\> Date::MONTHNAMES[(m % 12 ).succ]  
=\> “January”  
irb(main):025:0\> m = 1  
=\> 1  
irb(main):026:0\> Date::MONTHNAMES[(m % 12 ).succ]  
=\> “February”

HTH  
Robert

–

[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

All truth passes through three stages. First, it is ridiculed. Second,  
it is violently opposed. Third, it is accepted as being self-evident.  
Schopenhauer (attr.)

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [November 28, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/trouble-advancing-date-in-iterator/121441/3 "2007-11-28T20:42:30Z")

</div>

Thanks for your suggestions Robert. Looks like this is all I needed to  
do:

4 first\_month\_paid = first\_month\_paid \>\> (1)
