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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:58:47+00:00 2026-05-17T16:58:47+00:00

i have an array of vacation dates. These are always going to be weekdays.

  • 0

i have an array of vacation dates. These are always going to be weekdays. Lets say

DateTime[] dates = new DateTime[] {"1/8/2010","1/3/2010","1/6/2010","1/7/2010","1/21/2010"}

i now have a single input date. Lets say:

DateTime vacationDateToCheck = 1/7/2010;

i want to find the vacation set (list of dates) given the set above. In particular, i want the first and last date of the list.

So for example, if i pass in vacationDateToCheck variable (1/7/2010) i would get back

Yes, you are on vacation from 1/6/2010 to 1/8/2010.

If i pass in 1/4/2010 it would return an empty result.

Here is the kicker. I want it to factor in weekends and go across weekends. So if i have a vacation on a friday and on the following Monday, i would want it to include that as one list.

any suggestions?

  • 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-17T16:58:48+00:00Added an answer on May 17, 2026 at 4:58 pm

    First, you’ll have to sort your array, or at least make a sorted copy if it’s important that you keep the order in the original list. If you don’t, this isn’t going to be easy.

    Then, find the index of the element you’re checking for. Once you’ve done that, create a loop going forwards, and one going backwards in your array, and count the date you’ve reached in the loop if the two dates are consective; otherwise, stop that loop (and do the other loop if you haven’t done that already).

    This assumes that all days in the range you’re looking for can be found in the list, including weekends and holidays.

    EDIT: If you want to include weekends implictly, you’ll have to check the weekday using DayOfWeek while iterating over the days. The simplest way to do this is probably to also maintain a variable for the next expected day; every iteration in your loop, you add (or subtract, when moving backwards through the sorted array) one day. If the day you’re processing is a Friday (or Monday when moving backwards), add/subtract an additional 2 days to skip the weekend.

    Here’s the basic idea (not tested, but you should get the point). I’m assuming that you’ve sorted dates already, and that you’ve found the initial date in your array (at index i). For simplicity, I’m also assuming that vacationDateToCheck is never a Saturday or Sunday; if it can be either of those, you’ll have to adjust accordingly.

    DateTime expectedDate = vacationDateToCheck.AddDays(1);
    if (vacationDateToCheck.DayOfWeek == DayOfWeek.Friday)
      expectedDate = expectedDate.AddDays(2);
    DateTime startDate = vacationDateToCheck;
    DateTime endDate = vacationDateToCheck;
    for (int j = i + 1; i < dates.Length; i++) {
      if (dates[i] == expectedDate) {
        endDate = dates[i];
        expectedDate = dates[i].AddDays(1);
        if (dates[i].DayOfWeek == DayOfWeek.Friday)
          expectedDate = expectedDate.AddDays(2);
      } 
      else 
      {
        break;
      }
    }
    

    Iterating the other way is similar, only you add -1 and -2 days instead, and you check if the day of the week is a Monday.

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

Sidebar

Related Questions

Let's say I have array of bytes: byte[] arr = new byte[] { 0,
I have array object in jquery. array=[]; array{Id:user.Id,Date:user.Date}; Now am going to pass this
I have array of keywords. How can I find if any of these keywords
I have array of Objects (let say that class name is Snap) Snap. Is
Let's say I have array like {12,23,,34,22,,,12} If there are 5 items as than
I have array number = {2,3,4,5,6} Now i have to select rows from table
I have array that i had to unset some indexes so now it looks
I have array a = [aaa, bee, cee, dee] I want have new array
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>

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.