更新时间:2023-02-05 23:29:11
使用 SET DATEFORMAT 指定您希望输入的日期格式:
Use SET DATEFORMAT to specify the format you are expecting the date to be entered in:
SET DATEFORMAT DMY;
Declare @UserInput NVARCHAR(20)
set @UserInput = '26/07/2013'
select ISDATE(@UserInput)
我倾向于在输入到达 SQL-Server 之前执行此类验证,并确保任何日期变量都是日期.
I would be inclined to perform such validations prior to the input reaching SQL-Server, and ensuring that any date variables are dates.