• Conversion of 0 or other numbers directly to datetime is documented in SQL Server Books Online.

    select

    DT,

    FirstOfMonth = dateadd(mm,datediff(mm,0,a.DT),0),

    LastOfMonth = dateadd(mm,datediff(mm,-1,a.DT),-1)

    from

    ( --Test Data

    select DT = getdate() union all

    select DT = '20080214 14:37:25.867'

    ) a

    Results:

    DT FirstOfMonth LastOfMonth

    ----------------------- ----------------------- -----------------------

    2009-09-03 11:23:58.503 2009-09-01 00:00:00.000 2009-09-30 00:00:00.000

    2008-02-14 14:37:25.867 2008-02-01 00:00:00.000 2008-02-29 00:00:00.000