I'm extracting a date-formatted string (yyyy-MM-dd) and then converting it to a DateTime
and inserting it in the database using a storedprocedure. But I keep getting
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
The column in my table is of type date
.
I convert my string (e.g 2016-01-15
) by invoking DateTime.ParseExact(expirationDate, "yyyy-MM-dd", null)
and then I take that value and insert it as a parameter into my StoredProcedure and execute the proc.
But when using the debugger I can see that the return value is actually a yyyy-MM-dd HH:mm:ss
-formatted DateTime.
this is an example of how the code looks like
string expirationDate = GetDate();
DateTime date = DateTime.ParseExact(expirationDate, "yyyy-MM-dd", null);
ExecuteMyStoredProc(date);
DateTime
s don't have a format. They're a count of 100-nanosecond intervals since midnight on 01/01/0001. When you say "is actually ayyyy-MM-dd HH:mm:ss
-formatted DateTime." what you're actually saying is that when something (debugger, output window, a control, etc) converts theDateTime
into a string, to actually display it to you, it's using some particular format. That's an artifact of whatever's performing the conversion, not something inherent to theDateTime
value. – Damien_The_Unbeliever Jan 28 '14 at 9:18