Question : Isdate MSSQL not validating dates

Hi, I am using MSSQL 2005

I am uploading the data from Excel file in the temperory file.

In temperory file may date fields are nvarchar

In Excel file, I have the dates in the following form

17-Jan-07

when it goes transfers to temperory table I see in the form

17/01/2007 00:00:00

now when I make a query, it says this is not valid date

SELECT ISDATE('17/01/2007 00:00:00')

RETURNS 0

but If I do

SELECT ISDATE('01/17/2007 00:00:00')

returns 1


Why SELECT ISDATE('17/01/2007 00:00:00') is returning 0

Please help

Answer : Isdate MSSQL not validating dates

this is because it interprets the dates by default in the american format, which is MM/DD/YYYY ...
so 17/01 will be rejected, as 17 as month is not correct.

to solve that, you have to change the default language of the connection:

SET NOCOUNT ON
SET LANGUAGE 'english'
SELECT ISDATE('17/01/2007 00:00:00')
SELECT ISDATE('01/17/2007 00:00:00')
SET LANGUAGE 'german'
SELECT ISDATE('17/01/2007 00:00:00')
SELECT ISDATE('01/17/2007 00:00:00')

will return:
Changed language setting to us_english.
0
1
Changed language setting to Deutsch.
1
0

Random Solutions  
 
programming4us programming4us