MSSQL Woe’s….

This is probably me just being stupid, but I have spent the last 4 hours trying to work out how to input dates into MSSQL in dd/mm/yyyy format.

Originally I was trying to format them in the C# web application I was running, but as the culture is set to en-GB DateTime will only store them in dd/mm/yyyy format. According to the documentation for MSSQL you can only input in mm/dd/yyyy or yyyy/mm/dd format unless the localisation has been set for the server. I can’t change that as its a clients server, yet they would like to display the dates in UK format.

As seems to be the case with MS stuff it isn’t immediately clear how to do this, as I already mentioned the dates have to be stored in dd/mm/yyyy format due to the culture setting of the App. The solution is a lot easier than what I was thinking I was going to have to do which was change teh culture back to en-US and then format all the dates that are being displayed back into UK format.

You simply have to execute the SQL command “SET dateformat dmy;” before the INSERT statement that inputs the dates into the database. Easy.

I wish I had found that out 4 hours ago though. My excuse is its Friday!!