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??
Use this:
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date.ToShortDateString();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With