开发者

Why ISDATE() function return true for '9966'?

开发者 https://www.devze.com 2023-04-12 18:56 出处:网络
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

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

  1. why 开发者_JS百科it happens like that?
  2. 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) 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号