title: Count days of daterange in daterange
body: <p>I want to count how many days of a start and end-date are inside another start and end-date. Basically: How many days of the date 01.06.2020 - 06.06.2020 are inside the date 03.06.2020 - 31.12.2020. In this case the answer would be 4. The 3rd, 4th, 5th and 6th of June 2020.</p>
  
  <p>I know that I can use TIMESTAMPDIFF to do calculations between 2 dates, but I can't wrap my head around a simple solution to do it with 2 dates inside 2 dates.</p>
  
  <p>I can't believe nobody ever asked that question, but I can't find any solution to this.</p>
  
  <p>Simple table:</p>
  
  <pre><code>+-------------+--------------+
  | Start_date  |  End_date    | 
  +-------------+--------------+          
  | 2020-06-03  |  2020-12-31  |
  | 2014-09-08  |  2015-09-07  | 
  | 2015-01-15  |  2015-02-01  |
  +-------------+--------------+
  </code></pre>
  
  <p>I look for something along the lines of:</p>
  
  <pre><code>SELECT * FROM available_dates WHERE TIMESTAMPDIFF(DAY,'2020-06-01','2020-06-06', Start_date, End_date) &gt; 5
  </code></pre>