开发者

linq select distinct date from a DataTable

I want to fetch distinct date from a DataTable. Currently I'm using the below code:

MyDataTable.DefaultView.ToTable(true, "MyDateColumn");

This code considers the time too but I don't want the time to be considered. I wrote the below code to select only Date Part but while making the distinct it considers t开发者_JS百科he time too.

MyDataTable.AsEnumerable()
      .Select(row => new { MyDateColumn = row.Field<DateTime>("MyDateColumn").ToString("d") }).Distinct();

Please help me to select only distinct date(i.e by ignoring time).


You can try Selecting the column by just the Date property of the column:

MyDataTable.AsEnumerable()
      .Select(row => row.Field<DateTime>("MyDateColumn").Date).Distinct();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜