zoukankan      html  css  js  c++  java
  • linq 日期分组统计

     #region
            string Condition(DateTime date, string type)
            {
                if (date == null)
                {
                    date = DateTime.MinValue;
                }

                if (type == "day")
                {
                    return date.ToString("yyyy-M-d");
                }
                else if (type == "month")
                {
                    return date.ToString("yyyy-M");
                }
                return date.Year.ToString();
            }
            public void xx()
            {
                List<DateTime> datelist = new List<DateTime>();
                var today = DateTime.Now.Date;
                for (var i = 0; i < 7;i++ )
                {
                    datelist.Add(today.AddDays(-i));
                }

                var oderlist = this.Find().AsEnumerable();
                var result = from m in datelist
                             join n in oderlist on Condition(m, "day") equals Condition(n.create_time, "day") into c
                             from cc in c.DefaultIfEmpty()
                             group cc by Condition(m, "day") into g
                             select new { g.Key, Total = (g.FirstOrDefault()==null?0:g.Count())};

                var ccc = result.ToList();

            }
            #endregion
  • 相关阅读:
    字符编码 进制转换
    Android工具HierarchyViewer 代码导读(1) 功能实现演示
    jQuery中的bind(), live(), on(), delegate()
    [转]ActionScript3.0中XML处理方法
    Pane和Panel的区别
    [转]在命令行中编译运行Java Applet
    [转]关于五险一金,你知道多少?
    [转]ActionScript3.0对象深复制
    [转]用Flashbug调试Flash
    [转]用EditPlus搭建简易的Java开发环境
  • 原文地址:https://www.cnblogs.com/waitingfor/p/4321452.html
Copyright © 2011-2022 走看看