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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:10:26+00:00 2026-06-02T18:10:26+00:00

Given a start date, how do I find the larger and nearest start date

  • 0

Given a start date, how do I find the larger and nearest start date from a list?

Here’s my code but my way of getting the nearest one seems to be incorrect:

Activity oActivityNearestLarger = null;

List<Activity> oActivityByStartDateList = ClassForDBCalls.ActivityLISTByOutingID(iOutingID)
    .OrderBy(a => a.StartDate)
    .ToList();

long lLeastTicksDifference = 0; // initialize
int iIndexOfTheNearestLargerActivity = 0;

for (int i = 0; i < oActivityByStartDateList.Count; i++)
{
    // the start of the loop, set the lRecordTicksDifference
    if (i == 0)
    {
        lLeastTicksDifference = Math.Abs(oActivityByStartDateList[0].StartDate.Value.Subtract(dtStartDate).Ticks);
    }

    long lCurrentTicksDifference = Math.Abs(oActivityByStartDateList[i].StartDate.Value.Subtract(dtStartDate).Ticks);

    // get the larger, closest start datetime in the activities for the outing
    if (oActivityByStartDateList[i].StartDate > dtStartDate)
    {
        //  is the current activity startdate closer 
        //  to the to be added startdate (is it the nearest to the datetime being added?)
        if (lCurrentTicksDifference <= lLeastTicksDifference)
        {
            // if it has the least difference (meaning closer) store it for comparison in the next iteration
            lLeastTicksDifference = lCurrentTicksDifference;

            oActivityNearestLarger = oActivityByStartDateList[i];

            // set the index to be used to determine the Activity previous to it
            iIndexOfTheNearestLargerActivity = i;
        }
    }
}

Thanks in advance!

  • 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-02T18:10:28+00:00Added an answer on June 2, 2026 at 6:10 pm

    Will this not do it?

    Activity nearestToStart = 
        lassForDBCalls.ActivityLISTByOutingID(iOutingID)
        .OrderBy(a => a.StartDate)
        .FirstOrDefault(a => a.StartDate >= myStartDate)
    

    Or am I missing something?

    Sorry, just saw how dumb that first attempt was

    Activity nearestToStart = 
        lassForDBCalls.ActivityLISTByOutingID(iOutingID)
        .Where(a => a.StartDate >= myStartDate)
        .OrderBy(a => a.StartDate)
        .FirstOrDefault()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
Given the code below ... Net::HTTP.start('localhost', 4000) do |http| # # usual stuff omitted
I have a start date(mm/dd/yyyy) in javascript... I need to find out the exact
Find third Sunday of each month occur between given below two dates . Start
To find a specific date after some given date in SQL oracle. Example: Date
How can I find the start-date and name (1, 2, 3, etc.) of a
am trying to get the date and modify on it here is the code
Given a start date time , an end date time and a repeat until
how do I compute the business days in a week given the parameters: start
Given just a std::string iterator, is it possible to determine the start and end

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.