c#取时间范围技巧

//取当前整个星期时间范围
DateTime startDate = DateTime.Today.Date.AddDays(-(int)DateTime.Today.DayOfWeek), // prev sunday 00:00
endDate = startDate.AddDays(7); // next sunday 00:00
//取当前整个月时间范围
int CurrentYear = DateTime.Today.Year;
int CurrentMonth = DateTime.Today.Month;
DateTime startDate = new DateTime(CurrentYear, CurrentMonth, 1);
DateTime endDate = startDate.AddMonths(1).AddMinutes(-1);

//使用

var v = from x in doc.Descendants("Transaction")
        where ((DateTime)x.Element("Current_Date")).Date >= startDate
        && ((DateTime)x.Element("Current_Date")).Date < endDate
        select new Transaction(x);
posted @ 2013-04-20 17:58  黎东海  阅读(750)  评论(0编辑  收藏  举报