• 获取时间段:本周、本月、本年


                       case "本周内":      
    DateTime retStartDay = DateTime.Now.Date.AddDays(-(int)(DateTime.Now.DayOfWeek) + 1 );
    DateTime retEndDay = DateTime.Now.Date.AddDays(7 - (int)(DateTime.Now.DayOfWeek)).AddDays(1);
    sbSqlDate.Append("JoinDate >= '" + retStartDay + "' and JoinDate<= '" + retEndDay + "'");
    break;
    case "本月内":
    DateTime monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
    DateTime monthEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month+1,1).AddDays(-1);
    sbSqlDate.Append("JoinDate >= '" + monthStart + "' and JoinDate<= '" + monthEnd + "'");
    break;
    case "本年内":
    DateTime yearStart = new DateTime(DateTime.Now.Date.Year, 1, 1);
    DateTime yearEnd = new DateTime(DateTime.Now.Date.Year+1, 1,1).AddDays(-1);
    sbSqlDate.Append("JoinDate >= '" + yearStart + "' and JoinDate<= '" + yearEnd + "'");
    break;
                List<Radio> radList = radGrop.CheckedItems;
    foreach (Radio item in radList)
    {
    switch (item.BoxLabel)
    {
    case "不记得":
    break;
    case "昨天": sbSqlDate.Append("CreateDate >='" + new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(-1) + "' and CreateDate<'" + new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + "'");
    break;
    case "今天": sbSqlDate.Append("CreateDate='" + DateTime.Now.Date + "'");
    break;
    case "以前7天内": sbSqlDate.Append("CreateDate >= '" + DateTime.Now.AddDays(-7) + "' and CreateDate<= '" + DateTime.Now + "'");
    break;
    case "以前30天内": sbSqlDate.Append("CreateDate >= '" + DateTime.Now.AddDays(-30) + "' and CreateDate <='" + DateTime.Now + "'");
    break;
    case "本周内":
    DateTime retStartDay = DateTime.Now.Date.AddDays(-(int)(DateTime.Now.DayOfWeek) + 1);
    DateTime retEndDay = DateTime.Now.Date.AddDays(7 - (int)(DateTime.Now.DayOfWeek)).AddDays(1);
    sbSqlDate.Append("CreateDate >= '" + retStartDay + "' and CreateDate<= '" + retEndDay + "'");
    break;
    case "本月内":
    DateTime monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
    DateTime monthEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 1).AddDays(-1);
    sbSqlDate.Append("CreateDate >= '" + monthStart + "' and CreateDate<= '" + monthEnd + "'");
    break;
    case "本年内":
    DateTime yearStart = new DateTime(DateTime.Now.Date.Year, 1, 1);
    DateTime yearEnd = new DateTime(DateTime.Now.Date.Year + 1, 1, 1).AddDays(-1);
    sbSqlDate.Append("CreateDate >= '" + yearStart + "' and CreateDate<= '" + yearEnd + "'");
    break;
    case "指定日期": sbSqlDate.Append("CreateDate >= '" + dfStateDate.Text.Trim() + "' and CreateDate <='" + (dfEndDate.Text.Trim() == "0001-1-1 0:00:00" ? DateTime.Now.ToString() : dfEndDate.Text.Trim()) + "'");
    break;
    }
    }




    作者:PEPE
    出处:http://pepe.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    linux -- 部署java服务器(3) linux安装redis
    linux 安装php8
    linux mysql查看日志
    linux mysql常用的命令
    perl heredoc
    perl数值进制
    提问的智慧
    How to ask question the smart way
    PERL命令行
    图灵/异步图书
  • 原文地址:https://www.cnblogs.com/PEPE/p/2222849.html
Copyright © 2020-2023  润新知