Background Info: See SQL: ISDATE(@foo) and CAST(@foo AS smalldatetime) and the incorrect Updated IsSmallDate function
Oskar Austegard
http://mo.notono.us
--Checks if a string is a valid smalldatetime --Updated 04/03/06 by Oskar Austegard after bug find by Mounir Ben Hamed CREATE FUNCTION dbo.IsSmallDate ( @SmallDateString varchar(20) --The input string to check ) RETURNS BIT AS BEGIN DECLARE @Result bit SET @SmallDateString = LTRIM(RTRIM(@SmallDateString)) IF ISDATE(@SmallDateString) = 1 AND CONVERT(datetime, @SmallDateString) BETWEEN '1900-01-01' AND '2079-06-06' SET @Result = 1 ELSE SET @Result = 0 RETURN @Result END