zoukankan      html  css  js  c++  java
  • 获取时间段:本周、本月、本年

                       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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    转:为什么要有Spring?
    转:jsp与servlet的区别与联系
    转 原生js canvas实现苹果电脑mac OS窗口最小化效果
    JavaFX
    salesforce零基础学习(九十八)Type浅谈
    Salesforce LWC学习(十七) 前端知识之 onclick & onblur & onmousedown
    salesforce零基础学习(九十七)Event / Task 针对WhoId的浅谈
    salesforce零基础学习(九十六)Platform Event浅谈
    Salesforce LWC学习(十六) Validity 在form中的使用浅谈
    Salesforce LWC学习(十五) Async 以及 Picklist 公用方法的实现
  • 原文地址:https://www.cnblogs.com/PEPE/p/2222849.html
Copyright © 2011-2022 走看看