Asp.Net。从数据集中查找最小日期

时间:2014-09-01 06:53:23

标签: asp.net

我想从数据集中获取最小日期,但代码没有在不同时间给出最短日期..请建议我某种方式..

Report.StartDate = DateTime.Parse(ds.Tables[0].Compute("MIN([" + c.ColumnMap + "])", "").ToString());

1 个答案:

答案 0 :(得分:1)

试用此代码 -

 DateTime minDate = DateTime.MaxValue;
    DateTime maxDate = DateTime.MinValue;
    foreach (string dateString in StringDates)
    {
        DateTime date = DateTime.Parse(dateString);
        if (date < minDate)
            minDate = date;
        if (date > maxDate)
            maxDate = date;
    }

OR

 //Retrieve Minimum Date
    var MinDate = (from d in dataRows select d.Date).Min();

    //Retrieve Maximum Date
    var MaxDate = (from d in dataRows select d.Date).Max();