Select records from start of month to current date

Hani Honey picture Hani Honey · Sep 13, 2011 · Viewed 6.9k times · Source

I'm trying to select records that were added to the database between the start of the current month and the current day - I more or less know how to get records from the current day, and within a specific time period - but how do I get it so it starts from the beginning of the current calendar month?

Answer

Aaron Bertrand picture Aaron Bertrand · Sep 13, 2011
DECLARE @sm DATETIME;
SET @sm = DATEADD(DAY, 1-DAY(GETDATE()), DATEDIFF(DAY, 0, GETDATE()));

SELECT columns 
    FROM dbo.foo 
    WHERE datetime_column >= @sm;