Reputation: 49
I had set the date datatype to date in sql server but when i want get value from it will output datetime value "9/22/2016 12:00:00 AM".
DataGridViewRow row = cell.OwningRow;
string DATE = row.Cells[2].Value.ToString();
Upvotes: 0
Views: 135
Reputation: 257
Convert string into datetime and you can give the format like this way ... it will works....
DateTime d=Convert.ToDateTime(row.Cells[2].Value.ToString());
textBox1.Text = d.ToShortDateString();
Upvotes: 0
Reputation: 3141
Convert the date to the desired format
DateTime DATE = Convert.ToDateTime(row.Cells[2].Value.ToString();
When you want to display the DATE, use the format "yyyy-MM-dd" (as per your screen shot).
Upvotes: 0
Reputation: 8892
Ok, you are usting ToString()
method and it returns string
value. You can retrieve DateTime
with explicit casting:
DataGridViewRow row = cell.OwningRow;
DateTime DATE = (DateTime) row.Cells[2].Value;
Upvotes: 2
Reputation: 7087
You need to format it on the front end:
((DateTime)row.Cells[2].Value).ToString("dd-MM-yyyy");
Upvotes: 3