Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 784313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:41:34+00:00 2026-05-14T20:41:34+00:00

I have a date range that I would like to be able to loop

  • 0

I have a date range that I would like to be able to loop through in reverse. Give the following, how would I accomplish this, the standard Range operator doesn’t seem t be working properly.

>> sd = Date.parse('2010-03-01')
=> Mon, 01 Mar 2010
>> ed = Date.parse('2010-03-05')
=> Fri, 05 Mar 2010
>> (sd..ed).to_a
=> [Mon, 01 Mar 2010, Tue, 02 Mar 2010, Wed, 03 Mar 2010, Thu, 04 Mar 2010, Fri, 05 Mar     2010]
>> (ed..sd).to_a
=> []

as you can see, the range operator works properly form start to end, but not from end to start.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:41:35+00:00Added an answer on May 14, 2026 at 8:41 pm

    Try upto/downto :

    irb(main):003:0> sd = Date.parse('2010-03-01')
    => #<Date: 4910513/2,0,2299161>
    irb(main):004:0> ed = Date.parse('2010-03-15')
    => #<Date: 4910541/2,0,2299161>
    irb(main):005:0> sd.upto(ed) { |date| puts date }
    2010-03-01
    2010-03-02
    2010-03-03
    2010-03-04
    2010-03-05
    2010-03-06
    2010-03-07
    2010-03-08
    2010-03-09
    2010-03-10
    2010-03-11
    2010-03-12
    2010-03-13
    2010-03-14
    2010-03-15
    => #<Date: 4910513/2,0,2299161>
    irb(main):006:0> ed.downto(sd) { |date| puts date }
    2010-03-15
    2010-03-14
    2010-03-13
    2010-03-12
    2010-03-11
    2010-03-10
    2010-03-09
    2010-03-08
    2010-03-07
    2010-03-06
    2010-03-05
    2010-03-04
    2010-03-03
    2010-03-02
    2010-03-01
    => #<Date: 4910541/2,0,2299161>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I would like to leverage with Zend_Search_Lucene . However,
In my controller controller, I have use Date.new to create a date object to
I am interested in any library which can do the following: I have a
I am creating a stored procedure that produces reports based on data in a
I have an asp.net c# website I'm developing with Visual Web Developer Express Edition
I have an interesting problem trying to represent complex schedule data in a database.
I have an XML file: <SMS> <Number>+447761692278</Number> <DateTime>2009-07-27T15:20:32</DateTime> <Message>Yes</Message> <FollowedUpBy>Unassigned</FollowedUpBy> <Outcome></Outcome> <Quantity>0</Quantity> <Points>0</Points> </SMS>
There are a lot of SQL Top N questions on stackoverflow but I can't
I'm trying to figure out how to create a sandbox area in my new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.