I'm reading values from Excel and inserting read rows to SQL, but I'm facing an issue with date columns.
From Excel I'm reading the dates as 23-08-2011 01:33:01, but in the database the values are stored as 2011-08-22 10:21:18.000.
Is there a way I can convert in C# (not in T-SQL) the date I'm reading to a yyyy-mm-dd 00:00:00:000 format? I want to convert 23-08-2011 01:33:01 to 2011-08-23 00:00:00:000.
DateTime object using DateTime.ParseExactDateTime object into SQL format using String.Format and the appropriate format string.See these two resources for guide how to create a DateTime format string:
Standard Date and Time Format Strings
Custom Date and Time Format Strings
DateTime excel = DateTime.ParseExact("23-08-2011 01:33:01", "dd-MM-yyyy hh:mm:ss", CultureInfo.InvariantCulture);
String sqlString = String.Format("{0:yyyy-MM-dd hh:mm:ss:ffff}", excel);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With