title: mySQL week function to match excel weeknum 16
body: <p>I am trying to figure out the syntax required to replicate the excel function of weeknum([date],16) that will achieve the same results in MySQL.</p>
  <p>Currently, EXCEL WEEKNUM 16</p>
  <pre><code>=WEEKNUM(DATE(2021,1,1),16) = 1
  </code></pre>
  <p>but all of the week functions in MySQL cannot replicate this, I also tried</p>
  <pre class="lang-SQL prettyprint-override"><code>select week('2021-01-01', 0) from dual; result = 0
  select week('2021-01-01', 1) from dual; result = 0
  select week('2021-01-01', 2) from dual; result = 52
  select week('2021-01-01', 3) from dual; result = 53
  select week('2021-01-01', 4) from dual; result = 0
  select week('2021-01-01', 5) from dual; result = 0
  select week('2021-01-01', 6) from dual; result = 53
  select week('2021-01-01', 7) from dual; result = 52
  </code></pre>
  <p>so as of now, my only option is to use CASE statements and manually +/- week numbers to match; however, this does not work for previous years when (again) trying to match to Excel WEEKNUM 16.</p>
  <p>There is currently a question and answer on StackOverflow : <a href="https://stackoverflow.com/questions/38567543/mysql-week-function-to-begin-with-saturday">MySQL week() Function to begin with Saturday</a> asking the very same question; however, I have tried the solution presented and it does not work.</p>
  <p>any help would be appreciated!</p>