I'm inserting some data from my C# program into SQL Server 2012. I have column in my table that is datetime type. My C# code:
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
// returns 2016-04-11 11:47:05.535
When I debug my application I can see that date is in correct format (same as above). But when I look into my database, this date is:
2016-11-04 11:47:05.537
Month and day are swapped. Why is this happening?
SELECT DATENAME(MONTH, YourDateTimeColumn)and see if you get the correct month.DateTimein C# anddatetime(ordatetime2) in SQL Server. Use parameters when sending the data from C# -> SQL Server. Just make sure you're using datetime datatypes throughout and you will not have formatting issues.stringin the C#. Once you've converted to string (in C# or SQL), you've opened yourself up to formatting issues.datetimevalue. Without that string conversion, the OP would not be reporting that "SQL" had switched the day/month values. You're the only person who seems to be mentioning display.