0

i have in c# this list of the Rendez-vous:

  • ID Date_Start Date_End

    1. 18/11/2016 08:00 18/11/2016 14:00
    2. 18/11/2016 09:00 18/11/2016 11:30
    3. 18/11/2016 14:00 18/11/2016 16:30
    4. 18/11/2016 17:30 18/11/2016 19:00

How I can check the part of time is busy or no ? for exemple how to check the part time from 18/11/2016 11:30 to 18/11/2016 14:00 is busy ?

thanks for your Response.

  • 1
    Possible duplicate of [How to know if a DateTime is between a DateRange in C#](http://stackoverflow.com/questions/4781611/how-to-know-if-a-datetime-is-between-a-daterange-in-c-sharp) – MacakM Nov 19 '16 at 15:11
  • @MacakM I think OP is actually looking for an overlap of date ranges, although it's unclear – ChaseMedallion Nov 19 '16 at 15:13

1 Answers1

0

It's hard to tell exactly what you're looking for from your question. My interpretation is that you want to know whether a given range of dates overlaps with any range in your list. Here's the code to do that:

Rendezvous[] rendezvous = ... // you already have this
DateTime startTime = ... // e. g. 18/11/2016 11:30
DateTime endTime = ... // e. g. 18/11/2016 14:00
var isBusy = rendezvous.Any(r => !(endTime < r.Date_Start || startTime > r.Date_End));
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152