James123 James123 - 1 year ago 104
SQL Question

How to get last day of last week in sql?

How to get last date of the lastweek in sql? I mean last sunday date using query?

Answer Source

Regardless of the actual DATEFIRST setting, the last Sunday could be found like this:

               -1 - (DATEPART(weekday, GETDATE()) + @@DATEFIRST - 2) % 7,
              ) AS LastSunday

Replace GETDATE() with a parameter @date to get the last Sunday before a particular date.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download