title: SQL 'Round' Up a Date to a Given Day of the week
body: <p>My company groups all tasks into individual weeks that end on a Thursday.  Thus a task due on 3/20/19 would be grouped into the 3/21 week and tasks due on 3/22 group into the 3/28/19 week.</p>
  
  <p>I'm looking to calculate this field (called duedate_Weekdue) based on an input duedate.</p>
  
  <p>The following works but doesn't seem like the simplest way to do this.  Anyone have more elegant methods?</p>
  
  <pre><code>Select 
  getdate() as duedate,
  datepart(yy,getdate()) as duedate_yr,
  datepart(ww,getdate()) as duedate_ww,
  CASE
      When datename(dw,Dateadd(day,1,getdate()))='Thursday' Then Dateadd(day,1,getdate())
      When datename(dw,Dateadd(day,2,getdate()))='Thursday' Then Dateadd(day,2,getdate())
      When datename(dw,Dateadd(day,3,getdate()))='Thursday' Then Dateadd(day,3,getdate())
      When datename(dw,Dateadd(day,4,getdate()))='Thursday' Then Dateadd(day,4,getdate())
      When datename(dw,Dateadd(day,5,getdate()))='Thursday' Then Dateadd(day,5,getdate())
      When datename(dw,Dateadd(day,6,getdate()))='Thursday' Then Dateadd(day,6,getdate())
      When datename(dw,Dateadd(day,0,getdate()))='Thursday' Then Dateadd(day,0,getdate())
  END as duedate_Weekdue;
  </code></pre>