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

  • SEARCH
  • Home
  • 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 3873972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:05:55+00:00 2026-05-19T22:05:55+00:00

i have four dates: First two are the beginning and end of a month

  • 0

i have four dates:

First two are the beginning and end of a month

start_m = Time.new(2010,1).beginning_of_month
end_m = Time.new(2010,1).end_of_month

and the last two, d1 and d2, with d1 <= d2

What i want is an array containing the day numbers that come from the intersection of start_m -> end_m and d1->d2

for example:

start_m = 2011-01-01
end_m = 2011-01-31
d1 = 2010-12-20
d2 = 2011-01-11

the result would be

[1,2,3 ... 11]

is there an easy approach to do this intersection?

  • 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-19T22:05:55+00:00Added an answer on May 19, 2026 at 10:05 pm
    require 'date'
    
    start_m = Date.parse('2011-01-01')
    end_m = Date.parse('2011-01-31')
    d1 = Date.parse('2010-12-20')
    d2 = Date.parse('2011-01-11')
    
    puts (start_m..end_m).to_a & (d1..d2).to_a
    

    See documentation for Array#& . Output:

    2011-01-01
    2011-01-02
    2011-01-03
    2011-01-04
    2011-01-05
    2011-01-06
    2011-01-07
    2011-01-08
    2011-01-09
    2011-01-10
    2011-01-11
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table dates as following dates one two three four date1 id1 id2
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
i have four tables user-question contains two columns: questionID, userID, the questions that the
I have tow tables the first d001 has two col: ACC_ID, ACC_NAME | |
I have four columns in a table: date entered, time entered, date completed, time
In a JSP page I have four sample dates like 01- dec , 15-
I have a date in the format of 2012-08-10. I want the first four
I have a variable that needs the first four lines stripped out before being
I have four Buttons that display the the date/time of calendars which are attributes

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.