Follwing steps will explain clearly.
select GETDATE()
-- Result: 2007-05-08 17:47:56.937
select DATEPART(dd, GETDATE())
-- Result: 8
select DATEADD(dd, - DATEPART(dd, GETDATE())+1, GETDATE())
-- Result: 2007-05-01 17:48:27.123
SELECT DATENAME(dw, DATEADD(dd, - DATEPART(dd, GETDATE()) + 1, GETDATE())) AS FirstDay
-- Result: Tuesday
No comments:
Post a Comment