Published on: 25 Nov, 2020

TSQL first day of month

Tumblr Digg Google Plus

If you need to get the first day of the month in TSQL. You can use the built-in DATEADD or DATEFROMPARTS function.

See the following TSQL Queries example.


DECLARE @CurrentDate Date = GetDate()

--First Option
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @CurrentDate), 0) AS FirstDayOfMonth

--Second Option
SELECT DATEFROMPARTS(YEAR(@CurrentDate),MONTH(@CurrentDate),1) AS FirstDayOfMonth

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.