T-SQL 101: 83 Determining if a string is a number or date with ISNUMERIC and ISDATE
Sometimes we need to determine whether a string is a date or whether it is a number.
In the first example above, I’m asking if the string ‘20190229’ is a valid date. You can see from the response (0) that it isn’t. That’s because even though it’s a valid date format, February in 2019 doesn’t have a 29th day. It’s not a leap year.
The value returned from the ISDATE function is a zero or a 1. Curiously, the return value is of data type int. You’d think that a function that starts with Is and tests something would return a bit data type instead. But that’s just one of the curiosities of T-SQL.
2021-02-01