Whatever your date settings in SQL Server, you can get any known format of date if it is consistent. If you are processing a data feed it is best to make it explicit, rather than to rely on the date format settings of your server (Oh boy, the errors that are caused when the server moves over the Atlantic) The simplest way to do this is if the day and month are reversed to what you expect (We brits like to go Day Month Year)
This means that ....
SELECT CONVERT(DATETIME,'25/3/2011',103)
.
.. and ...
SELECT CONVERT(DATETIME,'3/25/2011',101)
will give you the same DateTime
In your case, you have a bug, frankly since there is no known date format (international standard time format) in SQL Server that goes yyyy-dd-mm.
Instead, you have to resort to pesky string manipulation.
SELECT CONVERT(DATETIME,SUBSTRING(Thedate,6,5)
+'-'+LEFT(TheDate,4)+ RIGHT(TheDate,13),103)
FROM (SELECT '2011-10-08 17:02:21.000' AS theDate )f
but be there when they fix the bug!!
↧