Search code examples
sqlsql-serverdatetimedate

How to get date representing the first day of a month?


I need functionality in a script that will enable me to insert dates into a table.

What SQL do I need to insert a date of the format

01/08/2010 00:00:00

where the date is the first day of the current month. What do I need to change order that I can specify the month value? Thanks


Solution

  • The best and easiest way to do this is to use:

    SELECT DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0)
    

    Just replace GETDATE() with whatever date you need.