Reputation: 368
I had written stored procedure which returns date only not datetime i.e
CurrentDate 2013-10-06
So when i stored this result in dataset using da.fill( ) method, there inside the datatable it is stored in the format datetime resulting as 2013-10-06 12:00:00
How to solve this problem?
Upvotes: 2
Views: 14485
Reputation: 368
Thank You all guys, finally i followed this approach
foreach (DataRow dr in dt.Rows)
{
dr["date"] = DateTime.Parse((dr["date"].ToString())).ToShortDateString();
}
Which only returns date without time.
Upvotes: 3
Reputation: 3419
You can format the DateTime string to show only Date. Since .NET doesn't have a Date-Only Datatype, you have to filter the Date out of a DateTime object.
Choose the ToShortDateString()
Method and if you need a special format, then you have to use the ToString()
method and provide a format string which can be found easily if you google for "DateTime Format".
Upvotes: 0
Reputation: 409
A datetime is always stored with default time value as "12:00:00",u can only format it to your desire format,
ds.Table[0].rows[0][0].tostring("yyyy-MM-dd")
Upvotes: 1