Search code examples
sql-server-2005selectdateadddatepart

Select records from start of month to current date


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?


Solution

  • DECLARE @sm DATETIME;
    SET @sm = DATEADD(DAY, 1-DAY(GETDATE()), DATEDIFF(DAY, 0, GETDATE()));
    
    SELECT columns 
        FROM dbo.foo 
        WHERE datetime_column >= @sm;