title: How to gets the number of overlapping days between 2 ranges?
body: <p>let me explain the situation first - let's say i have 4 dates: BS, BE, PS, PE (S for start, E for end).
  I need to know how many days are over lapping when given those dates.
  for example : BE-05.01 , BS-10.01, PS-03.01, PE-07.01
  the result is: 3 (05.01, 06.01 and 07.01 are overlapping)</p>
  
  <p>I wrote the following code but it seems to messy and i want to check if maybe there is a simpler way to do this:</p>
  
  <pre><code>private static double GetNumOfOverLappingDays(DateTime BS, DateTime BE, DateTime PS, DateTime PE)
      {
          //case 1:
          //                  |--- B ---|
          //                  |----P ---|
  
          //case 2:
          //                  |--- B ---|
          //                          | --- P --- |
  
          //case 3:
          //                  |--- B ---|
          //          | --- P ---- |
  
          //case 4:
          //                  |--- B ---|
          //                     | - P - |
  
          //case 5:
          //                  |--- B ---|
          //              | -------- P -------- |
  
          double days = -1;
          bool isNotOverLap = (BS &gt; PE) || (PS &gt; BE);
  
          if (isNotOverLap == false)
          {
              //case 1
              if (BS == PS &amp;&amp; BS == PE)
              {
                  days = (PE - PS).TotalDays;
              }
              //case 2
              else if (BE &gt; PS &amp;&amp; BE &lt; PE)
              {
                  days = (BE - PS).TotalDays;
              }
              //case 3
              else if (BS &gt; PS &amp;&amp; BS &lt; PE)
              {
                  days = (PE - BS).TotalDays;
              }
              //case 4
              else if (BS &lt; PS &amp;&amp; BE &gt; PE)
              {
                  days = (PE - PS).TotalDays;
              }
              //case 5
              else if (BS &gt; PS &amp;&amp; BE &lt; PE)
              {
                  days = (BE - PS).TotalDays;
              }
          }
          return days+1;
      }
  </code></pre>
  
  <p>thanks in advance for any assitance,</p>
  
  <p>Amit</p>