We have a PC that runs a script every hour to pull data from an Oracle table and inserts it into a SQL table, so that we can report on some key metrics. All was fine until the start of August when it started inserted dates in US not UK format! i.e. Data for August 10th was inserted as "2011-10-08 17:02:21.000" when it should have been "2011-08-10 17:02:21.000". The PC definitely has UK set as its region and the collation of the table is Latin1_ General_ CI_AS, which I believe is correct for UK. Can anyone think of where I shoudl be looking as I've run out of ideas? Thanks.
asked Aug 11 '11 at 05:54 AM in Default
Have a look at [SET DATEFORMAT]
Or use a string format which always works for dates in SQL Server - eg YYYYMMDD hh:mm:ss.nnn: http://msdn.microsoft.com/en-us/library/ms189491.aspx
answered Aug 11 '11 at 06:12 AM
you might investigate using a trigger to check the inserted value but that may cause more issues. Can you import it to a staging table somewhere and do a sanity check on the data? Or replace the script with a SSIS package to handle the date format for you?
answered Sep 23 '11 at 09:10 AM
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 ....
. .. and ...
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.
but be there when they fix the bug!!
answered Sep 26 '11 at 11:40 AM