title: How to get the week of the month along with the date range in MYSQL
body: <p>I have the query which returns me the week of the month but I wanted the date range along with that. How do I alter my query to get the date range for the week.This is my query:</p>
  <pre><code>select 
   date,
   FLOOR((DAYOFMONTH(date) - 1) / 7) + 1 AS week,
   Concat('Week ',FLOOR((DAYOFMONTH(date) - 1) / 7) + 1) AS weekname 
  from table_test 
   where DATE_FORMAT(date,'%m/%Y')='&quot;.$monYear.&quot;'&quot; 
  group by week
  </code></pre>
  <p>Here the variable $monYear equals &quot;10/2017&quot;.</p>
  <p>The week starts from sunday to saturday and the first week of the month starts from 01
  So, the output should be like this:</p>
  <blockquote>
  <p>Week 1 : 01/10/2107 - 07/10/2017</p>
  <p>Week 2: 08/10/2017 - 14/10/2017</p>
  <p>Week 3: 15/10/2017 - 21/10/2017</p>
  <p>Week 4: 22/10/2017 - 28/10/2017</p>
  <p>Week 5: 29/10/2017 - 31/10/2017</p>
  </blockquote>
  <p>Ok so I tried this, its almost correct but it gives me wrong results for '09/2017'. It gives me 20170896 as startDay for week 1 (96 is wrong) and also it doesnt give me the slashes in between.</p>
  <pre><code>select date-dayofweek(date)+1 as startDay, 
  date+ 7 - dayofweek(date) as endDate,
  FLOOR((DAYOFMONTH(date) - 1) / 7) + 1 AS week,
  from table_test where DATE_FORMAT(date,'%m/%Y')='09/2017' group by week
  </code></pre>