how to iterate on date ranges

N

Newb Newb

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.
 
H

Heesob Park

2009/1/28 Newb Newb said:
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
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
 
R

Rob Biedenharn

2009/1/28 Newb Newb said:
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
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!

irb> require 'date'
=> true
irb> (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"]
irb> puts (Date.parse('2009-01-02') .. Date.parse('2009-03-31'))
2009-01-02..2009-03-31
=> nil
irb> 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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top