Monday, February 20, 2012

Is there any date function to get the last date of a month ?

Is there any date function available to get the last date of a month.
If not , How can I get it ?Hi, Sha
Use one of the following functions:
CREATE FUNCTION dbo.LastDayOfTheMonth(@.TheDate datetime)
RETURNS datetime AS
BEGIN
RETURN DATEADD(month, DATEDIFF(month, 0, @.TheDate) + 1, 0) - 1
END
CREATE FUNCTION dbo.LastDayOfTheMonth(@.TheDate datetime)
RETURNS datetime AS
BEGIN
RETURN DATEADD(month, 1, CONVERT(varchar(6), @.TheDate, 112) + '01') - 1
END

No comments:

Post a Comment