set dateformat dmy
select isdate('31/1/2012')
I thought by going into Change the format of numbers, dates, and times in Windows Control Panel that I wouldn’t have to SET DATEFORMAT DMY in sql?
So I made the change, omitted the set statment, and the isdate is still failing, what am I missing?
In SQL Server 2012 you can use
TRY_PARSEand specify a culture (e.g.en-gb). You can read aboutTRY_PARSEhere:http://msdn.microsoft.com/en-us/library/hh213126(v=sql.110).aspx
Much safer, of course, to use an unambiguous date format in the first place, and avoid all the culture nonsense. You can have the application convert user entry before it ever sees the database, or just avoid string input altogether – with a calendar control or drop downs you can dictate a safe format like
YYYYMMDDand not have to worry about regional, language or dateformat settings – never mind trusting that all users are enteringd/m/yvs.m/d/y…