Showing posts with label sql date 1900. Show all posts
Showing posts with label sql date 1900. Show all posts

Thursday, November 10, 2016

How to find start date of month in SQL Server?


SELECT DATEADD(month, DATEDIFF(month, 0, @date), 0) AS StartOfMonth

0 in date functions means 1/1/1900.
The above function first find the difference of total months from 1/1/1900.
It then adds the difference in 0 (1/1/1900) again which will land to the beginning date of month.