问题描述
所以我正在查看SQL Server中ISDATE SET DATEFORMAT mdy;
SELECT ISDATE('15 / 04/2008'); - 返回0.
SET DATEFORMAT mdy;
SELECT ISDATE('15 / 2008/04'); - 返回0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/15/04'); - 返回0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/04/15'); - 返回1.
最后一个例子返回1(一个有效的日期),但上面的日期格式doesn与函数表达式中的格式不匹配。我认为这是一个文件中的错误,但后来好奇地尝试了它自己,它实际上返回1。
那么为什么'2008/04/15'是有效的日期格式为mdy的日期?
文档在这里:
from
因此,如果给定的字符串不适用于设置的日期格式,它还会使用默认语言选项,该选项允许以格式比如y / m / d
So I was looking at the documentation for the ISDATE() function in SQL Server and saw this in the examples:
SET DATEFORMAT mdy;
SELECT ISDATE('15/04/2008'); --Returns 0.
SET DATEFORMAT mdy;
SELECT ISDATE('15/2008/04'); --Returns 0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/15/04'); --Returns 0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/04/15'); --Returns 1.
The last example returns 1 (a valid date) but the date format above doesn't match the format in the expression of the function. I thought it was a mistake in the documentation but then curiously tried it out myself and it does actually return 1.
So why is '2008/04/15' a valid date when the date format is mdy?
Documentation here: http://msdn.microsoft.com/en-us/library/ms187347(SQL.105).aspx
from http://msdn.microsoft.com/en-us/library/ms187347%28SQL.105%29.aspx#SessionSettingDependencies
So if the given string not applies to the set dateformat it also cecks the default language option which allows dates in a format like y/m/d
这篇关于SQL Server ISDATE()函数 - 有人可以解释这一点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!