Why ISDATE() function return true for '9966'?
I used the ISDATE()
Function to check whether a value is a Date. but when i put 9966
or any four digit numeric, the function returns true
- why 开发者_JS百科it happens like that?
- what is the best way to check a value whether it is a date?
Yes, ISDATE() function will not be reliable in some cases. So, you should learn How to Handle ISDATE() with care
the values in a ISDATE functions are first casted to datetime
and
if varchar datatype is used to stored formatted dates (ex YYYYMMDD), to check if it is valid date, you need not only to use ISDATE() function, but also use LEN() function
9966 is implicitly CASTable to datetime because it is 9966 days after 01 Jan 1900
Try this (0
is 01 Jan 1900)
SELECT DATEADD(day, 9966, 0)
精彩评论