Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get datagridview date column as ddMMyyyy

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??

like image 241
wren Avatar asked Feb 04 '26 19:02

wren


2 Answers

Use this:

var dateAndTime = DateTime.Now;       
var date = dateAndTime.Date.ToShortDateString();
like image 195
hassan.ef Avatar answered Feb 06 '26 07:02

hassan.ef


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.

like image 21
Mohamad Mousheimish Avatar answered Feb 06 '26 09:02

Mohamad Mousheimish