zoukankan      html  css  js  c++  java
  • C#根据当前时间确定日期范围(本周、本月、本季度、本年度)[转]

    c#版本:
              DateTime dt = DateTime.Now; //当前时间
                DateTime startWeek = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))); //本周周一
                DateTime endWeek = startWeek.AddDays(6); //本周周日
                DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初
                DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末
                
    //DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); //本月月末

                DateTime startQuarter 
    = dt.AddMonths(0 - (dt.Month - 1% 3).AddDays(1 - dt.Day); //本季度初
                DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1); //本季度末

                DateTime startYear 
    = new DateTime(dt.Year, 11); //本年年初
                DateTime endYear = new DateTime(dt.Year, 1231); //本年年末

    SQL版本:
    select   dateadd(day,   2   -   datepart(dw,getdate()),   getdate())   [星期一],dateadd(day,   8   -   datepart(dw,getdate()),   getdate())   [星期日]
  • 相关阅读:
    [IOI2013]Dreaming
    Lost Cows
    Mobile Service
    [POI2005]Bank notes
    [CTSC2007]动物园zoo
    [CF1093F]Vasya and Array
    [雅礼集训 2017 Day1]市场
    [APIO2014]序列分割
    [CEOI2004]锯木厂选址
    [APIO2010]特别行动队
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/1232427.html
Copyright © 2011-2022 走看看