I'm trying to add a DateTime
column to a DataTable
. I use that code:
DataTable dt = new DataTable();
dt.Columns.Add("date", typeof(DateTime));
But this requires a DateTime
with the format "dd.MM.yyyy HH:mm:ss".
What I want is only the date. So typeof(DateTime)
but only the date.
If you have a better way to do it, please tell me. My way is just an idea I had :)
Suggestions appreciated :)
EDIT:
I want to use the DataTable
as DataSource
of a Telerik RadGridView
. I'm using the CellFormatting
event and in it I try to fill the date in the RadGridView cells. Here you can see the snippet I use:
DateTime.ParseExact(e.CellElement.Value.ToString(), "dd.MM.yyyy HH:mm:ss", CultureInfo.CurrentCulture)
This will logically show the date combined with the time. But if I change it to
DateTime.ParseExact(e.CellElement.Value.ToString(), "dd.MM.yyyy", CultureInfo.CurrentCulture
it throws and exception that this is not a valid DateTime format because I used typeof(DateTime)
above. So it requires the time as well or else it will throw an exception.
EDIT2:
It's a Windows Forms application.