Tuesday, July 7, 2015

Set date to first day of the month and end day of the month

Set date to first day of the month:
SELECT DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0)

Set date to end day of the month:
SELECT EOMONTH(GETDATE())

Set date to last day of the previous month:
SELECT EOMONTH(GETDATE(), -1)

Remove milliseconds from datetime:
DECLARE @now DATETIME SET @now = GETDATE() SELECT @now SELECT DATEADD(ms, -DATEPART(ms, @now), @now)

Share/Bookmark