Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server ISDATE() Function - Can someone explain this?

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

like image 405
Jamie Avatar asked Apr 26 '12 10:04

Jamie


1 Answers

from http://msdn.microsoft.com/en-us/library/ms187347%28SQL.105%29.aspx#SessionSettingDependencies

The return value of ISDATE depends on the settings set by SET DATEFORMAT, SET LANGUAGE and default language option.

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

like image 76
amaters Avatar answered Sep 22 '22 06:09

amaters