问题描述
如何使用 T-SQL 找到年度的第一个星期一"?
How can I find "First Monday of the Year" using T-SQL ?
推荐答案
这是 ngruson 发布的链接中的示例 (http://sqlbump.blogspot.nl/2010/01/first-monday-of-year.html):
Here's the example from the link ngruson posted (http://sqlbump.blogspot.nl/2010/01/first-monday-of-year.html):
DECLARE @Date datetime DECLARE @Year int = 2012 SET @Date = DATEADD(YEAR, @Year - 1900, 0) SELECT DATEADD(DAY, (@@DATEFIRST - DATEPART(WEEKDAY, @Date) + (8 - @@DATEFIRST) * 2) % 7, @Date)
以上返回:
2012-01-02 00:00:00.000