Reputation: 33
I am calling a stored procedure in my code and the results are being loaded into a DataTable, here is a column from the Datatable.
However, the time portion of the date is not supposed to be there. In the stored procedure, I am doing this: "Cast(loan.OpenedDate as date) as OpenedDate". In SQL if I execute this stored procedure, it displays correctly as shown here.
Why would the results differ if the procedure is the same?
Upvotes: 0
Views: 182
Reputation: 4014
That's Because in Code it has DataType of DateTime because C# Doesn't have Date DataType
So what you do is Use DateTime.ToShortDateString Method
E.g
DateTime dateToDisplay = new DateTime(2009, 6, 1, 8, 42, 50);
dateToDisplay.ToShortDateString()
Upvotes: 1
Reputation: 217
There is no Date type in C#, only DateTime, so your SQL Date result is being converted to a DateTime.
Upvotes: 2