[英]Calculate the previous sundays date from a Date column?
I have a table that contains a field t.Processed_Date.我有一个包含字段 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服务器为 MS SQL Server 2017 标准
SELECT DATEADD(wk, DATEDIFF(wk, 6, Processed_Date), 6) as LastSunday
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.