First and last day of month using T-SQL

Just discovered the elegant way of getting the last day of the month in SQL Server 2012:

SELECT EOMONTH(CURRENT_TIMESTAMP)

Why is there not an equally elegant solution for the first day of the month? Here are four different ways. I like neither… :

SELECT DATEFROMPARTS(YEAR(GETDATE()), MONTH(GETDATE()), 1)
SELECT DATEADD(DD, -1 * DAY(GETDATE()) + 1, GETDATE())
SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)
SELECT DATEADD(DD, 1, EOMONTH(CURRENT_TIMESTAMP,-1))
SELECT GETDATE() - DAY(GETDATE()) + 1

Leave a Reply