all groups > sql server programming > november 2005 >
You're in the

sql server programming

group:

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


Is there any date function to get the last date of a month ? Sha
11/18/2005 10:21:02 PM
sql server programming:

Is there any date function available to get the last date of a month.
If not , How can I get it ?


RE: Is there any date function to get the last date of a month ? Razvan Socol
11/19/2005 12:32:03 AM
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
AddThis Social Bookmark Button