Try this one -
CREATE FUNCTION [dbo].[udf_GetLastDayOfMonth]
(
@Date DATETIME
)
RETURNS DATETIME
AS
BEGIN
RETURN DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @Date) + 1, 0))
END
Query:
DECLARE @date DATETIME
SELECT @date = '2013-05-31 15:04:10.027'
SELECT DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @date) + 1, 0))
Output:
-----------------------
2013-05-31 00:00:00.000
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…