Tuesday, December 18, 2007

Stored Procedure Syntax - Get the last day of the month

Obtains the last day of the month:
Select
CAST(
CAST(
CAST(Month(getDate()) AS VARCHAR)
+ '/'
+ CAST(DAY(DATEADD(d, -DAY(DATEADD(m,1,GETDATE())),DATEADD(m,1,GETDATE()))) AS VARCHAR)
+ '/'
+ CAST(YEAR(GETDATE()) AS VARCHAR)
AS VarChar
)
AS smalldatetime
)