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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:57:54+00:00 2026-06-17T16:57:54+00:00

I am trying to create a set of date ranges from a list of

  • 0

I am trying to create a set of date ranges from a list of dates.

These dates are present in my object. Basically I would iterate through each row and will keep on iterating and when the time-span difference is greater than 5 minutes I will stop and use the end points as a date range. I have an algorithm below but the problem is it excludes many data rows:

Please see below the sample data and desired output

**Sample Data**

  Start_Date   Start_Date_Time    Replicate
    12.12.2012   8:22:58            10
    12.12.2012   8:22:58            30
    12.12.2012   8:22:58            31
    12.12.2012   8:22:58            32
    12.12.2012   8:22:58            33
    12.12.2012   8:22:58            34 
    12.14.2012   9:49:27            54
    12.14.2012   9:49:27            55
    12.14.2012   9:49:27            78
    12.14.2012   9:49:27            99
    12.14.2012   9:58               120
    12.14.2012   9:58               140
    12.14.2012   9:58               142
    12/12/2012   9:59               144
    12/12/2012   9:59               146
    12/12/2012   9:59               148
    12/12/2012   9:59               150

**Desired Output**
Date Ranges
8:22:58-8:22:58   Replicate10-34
9:49:27-9:49:27   Replicate54-99
9:58-9:59         Replicate120-150

My code gives me results but it excludes many rows:

lf.ReplicateBlocks.OrderBy(x => x.InitiationDate);

The initiationDate above is the StartDate and Start Time. I have sorted the list above in ascending order to start from the minimum date/time:

 DateTime minimumDateTime = DateTime.MinValue;

 foreach (RunLog.Domain.Entities.ReplicateBlock rb in lf.ReplicateBlocks)
 {
   TimeSpan intervalMinutes = rb.InitiationDate.Subtract(minimumDateTime);

   if (intervalMinutes.TotalMinutes >= 5)
   {
     minimumDateTime = rb.InitiationDate;

     //minDates.Add(minimumDateTime);

     UserConfirmationErrors confirmationRun = new UserConfirmationErrors();
     confirmationRun.minDate = rb.InitiationDate;
     confirmationRun.replicateID = rb.ReplicateId;

     uc.userConfirmationList.Add(confirmationRun);
   }
 }

 List<RunLog.Domain.Entities.RunLogEntryDatesDisplay> reDisplay = new List<Domain.Entities.RunLogEntryDatesDisplay>();

 foreach (var minDate in uc.userConfirmationList)
 {
   RunLog.Domain.Entities.RunLogEntryDatesDisplay red = new Domain.Entities.RunLogEntryDatesDisplay();
   reDisplay.Add(new Domain.Entities.RunLogEntryDatesDisplay() { runDate = minDate.minDate, DateRange = string.Format("{0} - {1}", minDate.minDate, minDate.minDate.AddMinutes(5)), MinimumReplicateId = minDate.replicateID.ToString() });
 }

 //return reDisplay.OrderByDescending(t => t.runDate).ToList();
 return reDisplay;

Once the user Confirmation List with Date Ranges is formed, I send it to the view in the form of a checkbox list, users selects those dates and I take the selected dates and look for those records again below:

  var query = from d in selectedDates
                    from o in lf.ReplicateBlocks
                    where (d.Checked &&
                          o.InitiationDate >= d.runDate &&
                          o.InitiationDate <= d.runDate.AddMinutes(5))
                    select o;
  • 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-17T16:57:55+00:00Added an answer on June 17, 2026 at 4:57 pm

    I would tidy this up a bit. First create a class to represent your date range. With all the data in the there, you could even override the ToString() method to output the format you need e.g.

    public class ReplicationDateRange
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int StartId { get; set; }
        public int EndId { get; set; }
        public override string ToString()
        {
            return String.Format("{0}-{1} Replicate {2}-{3}", StartDate.ToShortDateString(), EndDate.ToShortDateString(), StartId, EndId);
        }
    }
    

    Then what you need to do is keep iterating the list until you hit a date which isn’t within 5 minutes of the last baseline, but also updating the end date/id of the current range. The following should achieve this:

    var dateRanges = new List<ReplicationDateRange>();
    DateTime baselineDate = DateTime.MinValue;
    ReplicationDateRange currentDateRange = null;
    foreach (var block in lf.ReplicationBlocks.OrderBy(x => x.InitiationDate))
    {
        if ((block.InitiationDate - baselineDate).TotalMinutes <= 5)
        {
            currentDateRange.EndDate = block.InitiationDate;
            currentDateRange.EndId = block.ReplicateId;
        }
        else
        {
            baselineDate = block.InitiationDate;
            currentDateRange = new ReplicationDateRange()
            {
                StartDate = block.InitiationDate,
                EndDate = block.InitiationDate,
                StartId = block.ReplicateId,
                EndId = block.ReplicateId
            };
            dateRanges.Add(currentDateRange);
        }
    }
    foreach (var d in dateRanges)
    {
        Console.WriteLine(d);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a list of birth days, ordered by the dates,
I'm trying to create a Set that contains instances of 'Vertex3<T>'. I'm having a
I'm trying to create a set of checkboxes that I can check and send
I am trying to create a set of WCF web services for an existing
I'm trying to dynamically create a set of labels in my XUL Runner application.
I'm trying to create a small set of classes implementing a safe flag pattern,
I'm trying to create a drawing tool set for the iPad and so far
I am trying to create a virtual directory and set it's permissions using IIS7
I am trying to create an android app that has the following: Theme set
I'm trying to create a string that has a set amount of different words

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.