如何将 SQL Server 日期列与当前周进行比较?
How do I compare an SQL Server date column against the current week?
例如:
WHERE [Order].SubmittedDate = *THIS WEEK*
您可以将日期转换为周数,并将其与当前日期的周数进行比较.同样,您还需要比较年份,以免获得去年的周数.
You could convert your date to a week number and compare this to the week number from the current date. Likewise, you'll need to compare the year as well, so that you don't get last year's weeks.
WHERE DATEPART(wk, [Order].SubmittedDate) = DATEPART(wk, GETDATE())
AND DATEPART(yy, [Order].SubmittedDate) = DATEPART(yy, GETDATE())
这篇关于如何使用 SQL Server 与当前周进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!