Q:

Invalid date error when parsing

I want to create an array of dates using the code below
arr = []
for i in (1..31) do
  arr << Date.new(2014, 9, i)
end

I get an "Invalid date" error. Is there a way to resolve this?

A:

Is there a way to resolve this?

You could replace 31 with 30, but there's another way to reference the last day. Many Date methods accept negative arguments to count backwards:
first_day = Date.new(2014, 9, 1) #=> #<Date: 2014-09-01 ((2456902j,0s,0n),+0s,2299161j)>
last_day = Date.new(2014, 9, -1) #=> #<Date: 2014-09-30 ((2456931j,0s,0n),+0s,2299161j)>

You can use this to create a Range:
september_range = first_day..last_day

Or an Array:
september_days = (first_day..last_day).to_a

