3 Ways to Reach First Day of Month in SQL Server

Hello to everyone,

In this article, I will try to give information about 3 ways to reach the first day of the month in SQL Server.

In SQL Server you may want to get the first day of the month in some cases.

You can easily do this using the code below.

Method 1

DECLARE @date date;
SET @date = '2023-10-15';
SELECT DATEADD(dd, -( DAY( @date ) -1 ), @date);

Method 2

DECLARE @date date;
SET @date = '2023-10-15';
SELECT DATEADD(month, DATEDIFF(month, 0, @date), 0);

Method 3

DECLARE @date DATETIME;
SET @date = '2023-10-15';
SELECT @date - DAY(@date) + 1;

When you run the above codes, you will see a result similar to the one below.

3 Ways to Reach First Day of Month in SQL Server

As you can see, we have learned 3 ways to reach the first day of the month.

Good luck to everyone in business and life.

113 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!