下面是我的代码:
DECLARE @dayscount int
SET @dayscount = CAST(DATEDIFF(day, CONVERT(VARCHAR(20), '21/02/2021', 103), CONVERT(VARCHAR(20), '22/02/2021',103)) AS int)
SELECT @dayscount
我得到这个错误:
Msg 241, Level 16, State 1, Line 2
转换日期和/或时间失败
从字符串
如果使用CONVERT函数,数据类型应该是date
类型而不是varchar
类型。
select CAST(DATEDIFF(day, CONVERT(date, '21/02/2021', 103), CONVERT(date, '22/02/2021',103)) AS int)