26 August 2014

Find First Day of Current Month

-- first day of month
-- with time zeroed out
SELECT CAST(DATEADD(DAY,-DAY(GETDATE())+1, CAST(GETDATE() AS DATE)) AS DATETIME) AS 'without time'

-- with time as it was
SELECT DATEADD(DAY,-DAY(GETDATE())+1, CAST(GETDATE() AS DATETIME)) AS 'with time'

Risultati:
without time
-----------------------
2014-08-01 00:00:00.000

with time
-----------------------
2014-08-01 15:08:54.313


Trovato qui.