1

I have a table that contains a field t.Processed_Date. I need to return the Previous sunday of that date. Everything I'm trying is not working.

DATEADD(day,
    -1 - (DATEPART(weekday, GETDATE()) + CAST(Processed_Date As date) - 2) % 7,
    GETDATE()
) As 'Last Sunday'

But this gives an error

Msg 206, Level 16, State 2, Line 3
Operand type clash: date is incompatible with int

Server is MS SQL Server 2017 standard

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Lee Barry
  • 13
  • 2
  • 2
    Does this answer your question? [Get previous Tuesday (or any given day of week) for specified date](https://stackoverflow.com/questions/33079774/get-previous-tuesday-or-any-given-day-of-week-for-specified-date) Note that the top solution there works irrespective of `DATEFIRST` – Charlieface Nov 22 '21 at 14:44

1 Answers1

2
SELECT DATEADD(wk, DATEDIFF(wk, 6, Processed_Date), 6) as LastSunday
huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99