• From somewhere on this site (don't have the URL to give credit)

    CREATE FUNCTION [dbo].[getMthEndDate] (@date datetime)

    RETURNS DATETIME

    AS

    BEGIN

    RETURN dateadd(month,1+datediff(month,0,@date),0) - 1

    END