How this query works to get first day of current month?
sql, sql-server, sql-server-2008, t-sql
Solution
Firstly
Datediff(month, 0, Getdate()) will give will give total months from 1900
and from 1900 you add the months returned by the above months, so you will get month's first date
Eg : if we take present month then
Datediff(month, 0, Getdate()) = 1349 months
and if you add 1349 months to the '1900/01/01' you will get this months first date '2012/06/01'
Problem
``` SELECT Dateadd(month, Datediff(month, 0, Getdate()), 0), 'First Day of Current Month' ``` Can anyone tell me how this query works to get the first day of current month?