Nick
Nick

Reputation: 5882

Advice on best practice for checking record falling between multiple dates

I'm looking to find out the most efficient pseudo-code in order to achieve the following conditions:

If anybody is able to assist with tbe psuedo code behind such a query, I'd be grateful.

It's for use within a LINQ query.

Upvotes: 0

Views: 190

Answers (2)

John Petrak
John Petrak

Reputation: 2928

To check if the event over laps a specific time frame use

Event.Start < TimeFrame.End && (Event.End == null) ? Event.Start.AddDays(1) : Event.End > TimeFrame.Start

Upvotes: 0

Aliostad
Aliostad

Reputation: 81660

If you define (S1, S2) as (S1, S2?? S1) then

condition will be met if:

  S2 >= D1 && D2 >= S1




        S1     S2
        |------|  
D1                     D2
|-----------------------|

            S1                  S2
            |-------------------|  
    D1                     D2
    |-----------------------|

    S1                  S2
    |-------------------|  
              D1                       D2
              |-----------------------|


    S1                        S2
    |-------------------------|  
              D1      D2
              |-------|

But the condition will not be met for these:

        S1                  S2
        |-------------------|  
D1  D2
|----|

S1   S2
|-----|  
          D1                       D2
          |-----------------------|

Upvotes: 1

Related Questions