How to iterate on date ranges

Hi...here me again
If user enters, 2 date parameters.i want to find all the folders between
these date ranges.
For example if the user enters 2009-01-02 and 2009-01-30.i want to make
check between these two dates.
I have done below code for single date parameter.but i don't know how to
iterate for two date ranges.
Dir.foreach("ChatHistory") do |folder_name|
  if folder_name == params[:e_date][1]
  @sub_folder = Array.new
  Dir.foreach(File.join("ChatHistory",folder_name)) do |sub_folder_name|
  @sub_folder << sub_folder_name
  end
  end
end
pls kindly assist me friends.

···

--
Posted via http://www.ruby-forum.com/.

You can make array of dates between two dates like this:

require 'date'
arr = ('2009-01-02'..'2009-01-30').select{|x| Date.parse(x) rescue nil}

Regards,

Park Heesob

···

2009/1/28 Newb Newb <revathy.p@angleritech.com>:

Hi...here me again
If user enters, 2 date parameters.i want to find all the folders between
these date ranges.
For example if the user enters 2009-01-02 and 2009-01-30.i want to make
check between these two dates.
I have done below code for single date parameter.but i don't know how to
iterate for two date ranges.
Dir.foreach("ChatHistory") do |folder_name|
if folder_name == params[:e_date][1]
@sub_folder = Array.new
Dir.foreach(File.join("ChatHistory",folder_name)) do |sub_folder_name|
@sub_folder << sub_folder_name
end
end
end

Hi...here me again
If user enters, 2 date parameters.i want to find all the folders between
these date ranges.
For example if the user enters 2009-01-02 and 2009-01-30.i want to make
check between these two dates.
I have done below code for single date parameter.but i don't know how to
iterate for two date ranges.
Dir.foreach("ChatHistory") do |folder_name|
if folder_name == params[:e_date][1]
@sub_folder = Array.new
Dir.foreach(File.join("ChatHistory",folder_name)) do |sub_folder_name|
@sub_folder << sub_folder_name
end

You can make array of dates between two dates like this:

require 'date'
arr = ('2009-01-02'..'2009-01-30').select{|x| Date.parse(x) rescue nil}

Regards,

Park Heesob

Why iterate a range of Strings when you can just use Dates!

require 'date'

=> true

(Date.parse('2009-01-02') .. Date.parse('2009-01-31')).map{|d|

d.to_s}
=> ["2009-01-02", "2009-01-03", "2009-01-04", "2009-01-05", "2009-01-06", "2009-01-07", "2009-01-08", "2009-01-09", "2009-01-10", "2009-01-11", "2009-01-12", "2009-01-13", "2009-01-14", "2009-01-15", "2009-01-16", "2009-01-17", "2009-01-18", "2009-01-19", "2009-01-20", "2009-01-21", "2009-01-22", "2009-01-23", "2009-01-24", "2009-01-25", "2009-01-26", "2009-01-27", "2009-01-28", "2009-01-29", "2009-01-30", "2009-01-31"]

puts (Date.parse('2009-01-02') .. Date.parse('2009-03-31'))

2009-01-02..2009-03-31
=> nil

puts (Date.parse('2009-01-02') .. Date.parse('2009-03-31')).to_a

I don't understand what you're trying to do

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

···

On Jan 28, 2009, at 12:56 AM, Heesob Park wrote:

2009/1/28 Newb Newb <revathy.p@angleritech.com>: