hi,
I''ve two dates say
input for example.,
date1 = ''2009-01-02'';
date2 = ''2009-01-10'';
Need to find date range array between date1 and date2.
output for example.,
Array{
[0]=>''2009-01-02'',
[1]=>''2009-01-03'',
[2]=>''2009-01-04'',
[3]=>''2009-01-05'',
[4]=>''2009-01-06'',
[5]=>''2009-01-07'',
[6]=>''2009-01-08'',
[7]=>''2009-01-09'',
[8]=>''2009-01-10''
)
Thanks in advance
Shankar.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Shankar Ganesh wrote:> hi,Hello.> > I''ve two dates say > > input for example., > date1 = ''2009-01-02''; > date2 = ''2009-01-10''; > > Need to find date range array between date1 and date2. > > output for example., > Array{ > [0]=>''2009-01-02'', > [1]=>''2009-01-03'', > [2]=>''2009-01-04'', > [3]=>''2009-01-05'', > [4]=>''2009-01-06'', > [5]=>''2009-01-07'', > [6]=>''2009-01-08'', > [7]=>''2009-01-09'', > [8]=>''2009-01-10'' > ) > Thanks in advance > Shankar.I''m not entirely clear on what you''re looking for. If you already have this data in an array, I suggest using select {}. I.e. data.select {|x| x >= date1 and x<= date2 } If you''re trying to fetch the data, perhaps you''re looking for conditions. I.e. conditions = [ ''date_column > ? AND date_column < ?'', date1, date2 ] Hope that helps. Cheers, Darrik -- Darrik Mazey Developer DMT Programming, LLC. P.O. Box 91 Torrington, CT 06790 office: 330.983.9941 fax: 330.983.9942 mobile: 330.808.2025 darrik-hYmAEBE3lWIoJ/VrfD3uVNBPR1lH4CV8@public.gmane.org To obtain my public key, send an email to darrik-3ZOItiUs85ODFug2jf9dzoDEJ8dgO5X3FNOCUTQkUI4@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can use Date ranges. If you have strings, you''ll need to Parsedate
them into dates first. String ranges won''t understand date overflow
(ie how many days in a month, months in a year etc.).
((1.year.ago.to_date)..(Date.today)).to_a.map{|x| x.to_s(:db)}
Julian
On 04/02/2009, at 4:55 PM, Shankar Ganesh wrote:
>
> hi,
>
> I''ve two dates say
>
> input for example.,
> date1 = ''2009-01-02'';
> date2 = ''2009-01-10'';
>
> Need to find date range array between date1 and date2.
>
> output for example.,
> Array{
> [0]=>''2009-01-02'',
> [1]=>''2009-01-03'',
> [2]=>''2009-01-04'',
> [3]=>''2009-01-05'',
> [4]=>''2009-01-06'',
> [5]=>''2009-01-07'',
> [6]=>''2009-01-08'',
> [7]=>''2009-01-09'',
> [8]=>''2009-01-10''
> )
> Thanks in advance
> Shankar.
> --
> Posted via http://www.ruby-forum.com/.
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Julian Leviston wrote:> You can use Date ranges. If you have strings, you''ll need to Parsedate > them into dates first. String ranges won''t understand date overflow > (ie how many days in a month, months in a year etc.). > > ((1.year.ago.to_date)..(Date.today)).to_a.map{|x| x.to_s(:db)} > > JulianThanks for your HELP. can you explain with example Julian ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What do you mean? Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 04/02/2009, at 5:23 PM, Shankar Ganesh <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > wrote:> > Julian Leviston wrote: >> You can use Date ranges. If you have strings, you''ll need to >> Parsedate >> them into dates first. String ranges won''t understand date overflow >> (ie how many days in a month, months in a year etc.). >> >> ((1.year.ago.to_date)..(Date.today)).to_a.map{|x| x.to_s(:db)} >> >> Julian > > Thanks for your HELP. > can you explain with example Julian ? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 4, 2009, at 12:55 AM, Shankar Ganesh wrote:> hi, > > I''ve two dates say > > input for example., > date1 = ''2009-01-02''; > date2 = ''2009-01-10''; > > Need to find date range array between date1 and date2. > > output for example., > Array{ > [0]=>''2009-01-02'', > [1]=>''2009-01-03'', > [2]=>''2009-01-04'', > [3]=>''2009-01-05'', > [4]=>''2009-01-06'', > [5]=>''2009-01-07'', > [6]=>''2009-01-08'', > [7]=>''2009-01-09'', > [8]=>''2009-01-10'' > ) > Thanks in advance > Shankar.> From: Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> > Date: February 4, 2009 1:08:15 AM EST > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Date Range Between Two Dates - NEED HELP > Reply-To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > You can use Date ranges. If you have strings, you''ll need to Parsedate > them into dates first. String ranges won''t understand date overflow > (ie how many days in a month, months in a year etc.). > > ((1.year.ago.to_date)..(Date.today)).to_a.map{|x| x.to_s(:db)} > > JulianJulian gave you almost everything. Are you asking about "Parsedate"? Try this: require ''date'' date1 = Date.parse(''2009-01-02'') date2 = Date.parse(''2009-01-10'') (date1..date2).to_a irb> puts (date1..date2).to_a 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 => nil Or to make it even more clear, try 2009-02-25 to 2009-03-05 irb> puts (Date.parse(''2009-02-25'')..Date.parse(''2009-03-05'')).to_a 2009-02-25 2009-02-26 2009-02-27 2009-02-28 2009-03-01 2009-03-02 2009-03-03 2009-03-04 2009-03-05 => nil -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---