title: How to get 'Monday Date' in MySQL?
body: <p>I have an Oracle SQL Query, which I am trying to re-write in MySQL.</p>
  
  <p>PS : The dates are just arbitrary here, in the actual scenario I use this custom query inside Tableau where it accepts user defined Dates.The "Reference Start Date"  is being compared to "Start Date".</p>
  
  <p>Part of the Oracle SQL query:</p>
  
  <pre><code>CASE WHEN psr.dt_orgn IS NULL THEN NULL 
  ELSE
  CASE WHEN CAST('2017-05-22' AS DATE) &gt;= CAST('2017-06-22' AS DATE) THEN TRUNC(psr.dt_orgn,'IW')
  ELSE TRUNC(psr.dt_orgn + ((CAST('2017-06-22' AS DATE)-CAST('2017-05-22' AS DATE))*(INTERVAL '1' DAY)),'IW')
  END
  END) week
  </code></pre>
  
  <p>The above uses an existing Calender table in a Database to convert dates into 'Week Start Dates' i.e Monday Date of that Week</p>
  
  <p>MySQL version:</p>
  
  <pre><code> CASE WHEN psr.originated IS NULL THEN NULL 
   ELSE
     CASE WHEN CAST('2017-05-22' AS DATE) &gt;= CAST('2017-06-22' AS DATE) THEN DATE_ADD(psr.originated, 
   INTERVAL - WEEKDAY(psr.originated) DAY)
   ELSE DATE_ADD(psr.originated + ((CAST('2017-06-22'AS DATE) - CAST('2017-05-22' AS DATE)) * (INTERVAL '1' DAY))
   END
   END) week
  </code></pre>
  
  <p>I am using a solution I found to get 'Week Start Date' in MySQL as follows:</p>
  
  <pre><code>   DATE_ADD(mydate, INTERVAL(1-DAYOFWEEK(mydate)) DAY)
  </code></pre>
  
  <p>And I am getting error while doing this.
  My question is how do I apply the same to the 2nd else condition with the '1 day Interval' in the MySQL query?</p>
  
  <p>Or is there an easier solution to get week start date in MySQL?</p>