Get First and Last day of Month
Ok, I know this is simple - but the snippet was in my archive so I'm going to post it. These two functions will return the first and/or last day of the month of the passed in datetime.Example:
CREATE FUNCTION GetFirstDayOfMonth
RETURN Convert(DateTime, '1/' + Convert(VarChar, Month(@DateTime)) + '/' + Convert(VarChar, Year(@DateTime)) + ' 0:0:0.0')
CREATE FUNCTION GetLastDayOfMonth
RETURN Convert(DateTime, Convert(VarChar, (DateAdd(MM, 1, @DateTime - Day(@DateTime) + 1) - 1), 101) + ' 23:59:59.99')
Is this code snippet, product or advice warrantied against ill-effect and/or technical malaise? No. No it's not! Not expressed - Not implied - not at all.