I want to get a DataColumn (of DataTime type) of my DataTable in List. How can I do this with LINQ?
I tried the following lines but didn't work:
DateTimeList = dt.Columns.Cast<DataColumn>()
.Where(dc => dc.DataType == typeof(DateTime)).ToList());
DateTime values are created like the follow one:
new DateTime(2019, 6, 17, 16, 46, 05)
To return a
List<DateTime>type from theDateTimecolumns in aDataTable:The query gets all the
DateTimevalues whether thedtcontains one or moreColumn<DateTime>type.If you have a single
DataColumn<DateTime>type in the table, you can write instead: