• A possible alternative is convert/cast with datetime styles (e.g. 112 for ISO in the form of yyyymmdd). This comes in often very handy for date calculations:

    declare @MyDate datetime

    set @MyDate = getdate()

    -- first day of given month (yyyymm01)

    select convert(datetime, convert(varchar, (year(@MyDate) * 10000) + (month(@MyDate) * 100) + 1), 112)

    -- last day of given month (first day of next minus one day -> yyyymm01 + 1 month - 1 day)

    select dateadd(month, 1, convert(datetime, convert(varchar, (year(@MyDate) * 10000) + (month(@MyDate) * 100) + 1), 112)) - 1

    Cheers, R.