您的位置:首页 > 数据库

How to check if a date is a valid date in Sql Server 2005

2008-04-02 14:32 681 查看
At times, in our stored procedures or sql queries, we need to check if the date specified in the variables is a valid date.

Use the ISDATE() function.

The
ISDATE() function determines whether the variable or the expression
contains a valid date. It returns 1(true) if the input expression is a
valid date; otherwise, it returns 0 (false).

For eg:

DECLARE @dt varchar(10)

SET @dt = '02/21/08'

SELECT ISDATE(@dt)

-- Returns 1

DECLARE @dt varchar(10)

SET @dt = '13/21/08'

SELECT ISDATE(@dt)

-- Returns 0 as 13 is not a valid month
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: