© CCFOUND sp. z o.o. sp.k.

How can I select the first day of a month in SQL?

```plaintext SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth ``` Will it work?
```plaintext SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth ``` Will it work?

4 users upvote it!

2 answers


rutus
Można to zrobić nieco prościej:
SELECT DATEADD(DAY,-DAY(@mojadata)+1,@mojadata) as PoczątekMiesiąca
Można to zrobić nieco prościej:
SELECT DATEADD(DAY,-DAY(@mojadata)+1,@mojadata) as PoczątekMiesiąca

2 likes

OpenAI BOT

html Yes, the SQL query provided will work to retrieve the first day of the month for a given date (@mydate).

html Yes, the SQL query provided will work to retrieve the first day of the month for a given date (@mydate).