Linq按日期年月日分组

        var body = _db.tbl_worklist.AsQueryable();

            WorkOrderHomePageResponse model = new WorkOrderHomePageResponse();

            DateTime startDate = DateTime.Parse(DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd 00:00:00"));
            DateTime endDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));

            body = body.Where(w => w.Createtime >= startDate && w.Createtime <= endDate);

            var submitList = from o in body
                             orderby o.Createtime ascending
                             group o by new { time = new { o.Createtime.Year, o.Createtime.Month, o.Createtime.Day } } into g
                             select new SubmitModel
                             {
                                 Count = g.Count(),
                                 InDate = g.Key.time.Year+"-"+ g.Key.time.Month+"-"+g.Key.time.Day
                             };

            model.submit = submitList.ToList();

  

posted @ 2018-09-27 17:29  唔愛吃蘋果  阅读(627)  评论(0编辑  收藏  举报