title: To pull last friday date
body: <p>I have this query to pull the last friday date with given a date. It works for all day except if the given date is today.</p>
  
  <blockquote>
    <p>select dateadd(d, -((datepart(weekday, getdate()) + 1 + @@DATEFIRST) %
    7), getdate())</p>
  </blockquote>
  
  <p>Taking for example, today is 2014-02-14. if i apply to the query above, the result returned is still 2014-02-14</p>
  
  <blockquote>
    <p>dateadd(d, -((datepart(weekday, '2014-02-14') + 1 + @@DATEFIRST) % 7),
    '2014-02-14')</p>
  </blockquote>
  
  <p>If i put as 2014-02-13 below, then it returned last friday date properly.</p>
  
  <blockquote>
    <p>select dateadd(d, -((datepart(weekday, '2014-02-13') + 1 +
    @@DATEFIRST) % 7), '2014-02-13')</p>
  </blockquote>
  
  <p>Can you help how i can i get last Friday date if given today is Friday.</p>