Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calculate the previous sundays date from a Date column?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

SELECT DATEADD(wk, DATEDIFF(wk, 6, Processed_Date), 6) as LastSunday
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading