On Sun, 23 Apr 2006, Marston A. wrote:

> What is the easiest way in Ruby to make an array our of a date range?
> Something like this:
>
> @date1 = "2006-04-01"
> @date2 = "2006-04-23"
>
> array = [@date1..@date2]
>
> Something like that would be an easy solution as @date1 and @date2 are
> going to by dynamic, but this doesn't work as they are strings.
>
> Or would I have to manually insert the ranges one by one myself?
>
> array = ["2006-04-01", "2006-04-02", ... , "2006-04-23"]
>
> Thanks for any help in advanced!

are you sure that you need an array:

       harp:~ > cat a.rb
       require 'date'

       a = Date.parse "2006-04-01"
       b = Date.parse "2006-04-23"

       (a .. b).each{|date| puts date}



       harp:~ > ruby a.rb
       2006-04-01
       2006-04-02
       2006-04-03
       2006-04-04
       2006-04-05
       2006-04-06
       2006-04-07
       2006-04-08
       2006-04-09
       2006-04-10
       2006-04-11
       2006-04-12
       2006-04-13
       2006-04-14
       2006-04-15
       2006-04-16
       2006-04-17
       2006-04-18
       2006-04-19
       2006-04-20
       2006-04-21
       2006-04-22
       2006-04-23


if you do simply use

   list = (a .. b).inject([]){|accum, date| accum << date}

regards.


-a
-- 
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama