DaveDev DaveDev - 3 months ago 8
SQL Question

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

Answer

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.

Comments