Hi i set the datasource of a datagridview to my sql statement which selects the date from a table in database, on the gridview itself it shows just fine as dd/mm/yyyy but when i get the value from the datagridview cell and convert it to string it becomes dd/MM/yyyy 12am, how do i remove the time??
Asked
Active
Viewed 245 times
3
-
1Possible duplicate of [Convert a string to a date in .net](https://stackoverflow.com/questions/123263/convert-a-string-to-a-date-in-net) – peeyush singh Apr 09 '19 at 08:07
2 Answers
1
Use this:
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date.ToShortDateString();

hassan.ef
- 1,300
- 2
- 11
- 19
1
You can use ToString() property. And pass it the format you want as a string. For example:
var today = DateTime.Now();
var formattedDate = today.ToString("dd/MM/yyyy");
This will solve your problem, in this way you can use the format that you want.

Mohamad Mousheimish
- 1,641
- 3
- 16
- 48