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 8020051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:34:51+00:00 2026-06-04T21:34:51+00:00

I need some clear mind to check if a date range false between another

  • 0

I need some clear mind to check if a date range false between another interval. Here is whats happening:

DateTime[] dates = new DateTime[20];
dates[0] = Convert.ToDateTime(initial_date);
for (int i = 1; i <= 19; i++)
{
dates[i] = initial_date.AddYears(i);
}

So i have an array that stores 20 dates. If the initial_date = 1/20/2012 the array goes from dates[0] = 1/20/2012 up to dates[19] = 1/20/2031
and now i want to check if a user selects two dates for example 1/1/2013 and 1/1/2014 the selections falls between the the first element of the array (dates[0]) and the second (dates[1]). so far:

DateTime a1 = Convert.ToDateTime(vtable.Rows[0][0]);
DateTime a2 = Convert.ToDateTime(vtable.Rows[vtable.Rows.Count - 1][0]);
DateTime start = DateTime.MinValue;
DateTime end = DateTime.MaxValue;
for (int i = 0; i < 20; i++)
            {
                if (a1.CompareTo(dates[i]) >= 0)
                {
                    start = dates[i];
                    for (int j = 19; j > 0 ; j--)
                    {
                        if (a2.CompareTo(dates[j]) >= 0)
                        {
                            end = dates[j]; 
                            break;
                        }
                    }
                    break;
                }
            }

this is working up to the point when a user selects a daterange that falls only between one element of the array. Like for example if the selection is 1/30/2012 – 5/30/2012 then start = date[0] and end = date[0]
I know i can simply state at the end if end == unassigned then end = start but i am thinking is better to correct the algorithm than applying a patch at the end
Thank you very much

  • 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-06-04T21:34:54+00:00Added an answer on June 4, 2026 at 9:34 pm

    Store your date ranges as pairs as in start to end, where end would next start – 1 day.

    Makes things much clearer in the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some clear mind thinking to provide some good suggestion how this kind
Need some best practice advice here... Navigation based application. Root view is a UITableView
Excuse me, I do not make a clear question in english. I need some
I need some help here. Here is my situation: I have a binding list
I need to clear some points regarding synchronization at block level. suppose following synchronization
I need to do some clean up work when I am going to terminate
I need to do testing on clean machines frequently so I need some kind
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some guidance figuring out what went wrong. I've been using mysql, phpmyadmin for

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.