Monthly Archives: November 2009

TSQL Date Only Function

By | Code, Database, MSSQL2005, MSSQL2008, Quick Tips, Software Development, SQL Server, TSQL | No Comments
CREATE FUNCTION [dbo].[DateOnly] (@DATE DATETIME)
RETURNS DATETIME
BEGIN
    RETURN DATEADD(d, DATEDIFF(d, 0, @DATE), 0)
END

TSQL Last Day Of The Month

By | Code, MSSQL2005, MSSQL2008, Quick Tips, SQL Server, TSQL | No Comments
CREATE FUNCTION [dbo].[LastDayOfTheMonth] (@DATE DATETIME )
RETURNS DATETIME
BEGIN
    RETURN dateadd(ms, -3, DATEADD(mm, DATEDIFF(m, 0, @DATE) + 1, 0))
END