SQL Server 2008 - ISDATE doesn't work with
I really don't understand this. The ISDATE function
doesn't work with new date and time types, whats more you can't pass it a string
representing a date before 1/1/1753.
Try this
select ISDATE('1/1/1700')
in SQL 2008 it will return 0.
Whats odd is that there is no function to cater for these new dates.
So whats your option, well someone that attended the jumpstart training I did
last month suggested using try catch. So here it is, a TSQL procedure to workout
if a date is valid for the new types.
create procedure ISDATE2(@date varchar(20))
as
begin
begin try
declare @d date = @date
return 1
end try
begin catch
return 0
end catch
end
go
declare @result
bit
exec @result
= dbo.isdate2
'1/1/1700'
select
@result
Unfortunately you can't have begin try in a function.
The other option is to use a CLR function.
-