两个字符两个字符来判断
substring(字段名,1,2)----好象年就没什么可判断的了
substring(字段名,3,2)----between
01
and
12,不在范围内就不算日期
substring(字段名,5,2)----这个有点麻烦,要结合月份来判断,譬如2月有时有28天有时29天,其他月份有的31天,有的30天,所以可以判断between
01
and
28的肯定可以判断正确,如果超过28的要结合月份及年份来判断了
思路是用函数转换,如果出错则不是日期,以下抛砖引玉之用
begin
declare
@c
varchar(10)
declare
@d
datetime
set
@c
=...
set
@d
=
convert(datetime
,@c)
if
@@error
>0
print
'不是日期'
end