Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要获取当月第一天的 tsql 日期时间以在查询中使用。
我想出了
declare @StartDate datetime set @StartDate = cast( MONTH( getdate()) as char(2))+ '/1/' + cast( Year( getdate()) as char(4)) select @StartDate
但是想知道一个更好的方法来做到这一点。
建议?
这个怎么样:
SELECT DATEADD(month, DATEDIFF(month, 0, getdate()), 0) AS FirstOfMonth
select dateadd(month, datediff(month, 0, getdate()), 0)