精华内容
下载资源
问答
  • python获取上一季度最后一天

    千次阅读 2019-10-09 21:39:19
    闲话少叙,直接上代码 from datetime import datetime def getlastseason(today): today = datetime.strptime(today, '%Y%m%d') quarter = (today.month - 1) / 3 + 1 if quarter == 1: return datetime...

    闲话少叙,直接上代码

    from datetime import datetime
    def getlastseason(today):
        today = datetime.strptime(today, '%Y%m%d')
        quarter = (today.month - 1) / 3 + 1
        if quarter == 1:
            return datetime(today.year - 1, 12, 31).strftime('%Y%m%d')
        elif quarter == 2:
            return datetime(today.year, 3, 31).strftime('%Y%m%d')
        elif quarter == 3:
            return datetime(today.year, 6, 30).strftime('%Y%m%d')
        else:
            return datetime(today.year, 9, 30).strftime('%Y%m%d')

    这个函数的参数是字符串日期,比如'20180101',返回的也是字符串的日期,函数调用如下:

    展开全文
  • 本周、本月、本季度、本年最后一天 """ import datetime # 获取常用特定日期(如去年/季度/当月/本周/首日/) # ======================================= # 关于年(今年,去年,明年) # ==================...
    
    """
    通过datetime和dateutil进行常用日期的获取
    如:
    今年,去年,明年
    当前季度
    本月,上月,去年同期,今年一月
    今天,昨天,明天,
    本周、本月、本季度、本年第一天,
    本周、本月、本季度、本年最后一天
    """
     
    import datetime
     
    # 获取常用特定日期(如去年/季度/当月/本周/首日/)
     
    # =======================================
    # 关于年(今年,去年,明年)
    # =======================================
    # 今年
    today = datetime.date.today()           # 都是基于today, 此时为'2019-02-22',下同
    today.year                              # out: 2019
     
    # 去年
    today = datetime.date.today()
    today.year-1                           # out : 2018
     
    # 明年
    today = datetime.date.today()
    today.year+1                           # out : 2020
     
     
    # =======================================
    # 关于季度(当前季度)
    # =======================================
    today = datetime.date.today()
    quarter = (today.month-1) // 3 + 1
    '{}Q{}'.format(today.year, quarter)          # out: '2019Q1'
     
     
    # =======================================
    # 关于月(本月,上月,当年1月,去年同月)
    # =======================================
    # 本月(月份)
    today = datetime.date.today()
    today.month                                        # out: 2
     
    # 本月(年月)
    today = datetime.date.today()
    datetime.datetime.strftime(today, "%Y-%m")             # out: '2019-02'
     
    # 上月
    today = datetime.date.today()
    last_month = today + datetime.timedelta(days=-today.day)
    # last_month.month                                     # 月份,out: 1
    datetime.datetime.strftime(last_month,"%Y-%m")             # out: '2019-01'
     
    # 上N个月
    from dateutil.relativedelta import relativedelta           # 需要引入新的包
    today = datetime.date.today()
    last_2_month = today + relativedelta(months=-2)           # 上两个月,上N个月参数为(months=-N)
    datetime.datetime.strftime(last_2_month, "%Y-%m")             # out: '2018-12'
     
    # 当年1月
    today = datetime.date.today()
    str(today.year) +'-01'              # out: '2019-01'
     
     
    # =======================================
    # 关于天
    # =======================================
    # 今天(天数)
    today = datetime.date.today()
    today.day
    # 今天(日期)
    today.isoformat()                # out: '2019-02-22'
     
    #  昨天
    today = datetime.date.today()
    yesterday = today + datetime.timedelta(days=-1)
    yesterday.isoformat()                                   # out: '2019-02-21'
     
    # 明天
    today = datetime.date.today()
    yesterday = today + datetime.timedelta(days=1)
    yesterday.isoformat()                                   # out: '2019-02-23'
     
    # 本周第一天
    today = datetime.date.today()
    week_start_day = today - datetime.timedelta(days=today.weekday())
    week_start_day.isoformat()                                   # '2019-02-18',周一
     
    # 本周最后一天
    today = datetime.date.today()
    week_end_day = today + datetime.timedelta(days=6-today.weekday())
    week_end_day.isoformat()                                   # '2019-02-24',周天
     
    # 本月第一天
    today = datetime.date.today()
    month_start_day = today - datetime.timedelta(days=today.day-1)
    month_start_day.isoformat()                                   # '2019-02-01',当月第一天
     
    # 本月最后一天
    from dateutil.relativedelta import relativedelta            # 引入新的包
    today = datetime.date.today()
    # 必须先置为首日,直接用relativedelta(months=1,days=-today.day+1)会有错误结果
    month_end_day = (today + datetime.timedelta(days=-today.day+1)) + relativedelta(months=1,days=-1)
    month_end_day.isoformat()                                    # '2019-02-28',当月最后一天
     
    # 本季度第一天
    today = datetime.date.today()
    quarter_start_day = datetime.date(today.year,today.month - (today.month - 1) % 3, 1)
    quarter_start_day.isoformat()                              # '2019-01-01'  ,本季度第一天
     
    # 本季度最后一天
    from dateutil.relativedelta import relativedelta           # 引入新的包
    today = datetime.date.today()
    quarter_end_day = datetime.date(today.year,today.month - (today.month - 1) % 3 +2, 1) + relativedelta(months=1,days=-1)
    quarter_end_day.isoformat()                                # '2019-03-31'  ,本季度最后一天
     
    # 本年第一天
    today = datetime.date.today()
    year_start_day = datetime.date(today.year, 1, 1)
    year_start_day.isoformat()                                      # '2019-01-01'  ,本年第一天
     
    # 本年最后一天
    today = datetime.date.today()
    year_end_day = datetime.date(today.year+1, 1, 1) - datetime.timedelta(days=1)
    year_end_day.isoformat()                                        # '2019-12-31' ,本年最后一天
    
    展开全文
  • Python 获取当前季度最后一天的日期

    千次阅读 2018-12-05 20:12:12
    做数据分析绕不开“季度末”,那么Python中怎么获得当前季度最后一天的日期呢? from datetime import datetime as dt def getql(): today=dt.now() quarter = (today.month-1)/3+1 if quarter == 1: return ...

    做数据分析绕不开“季度末”,那么Python中怎么获得当前季度最后一天的日期呢?

    from datetime import datetime as dt
    def getql():
        today=dt.now()
        quarter = (today.month-1)/3+1
        if quarter == 1:
            return dt(today.year,3,31)
        elif quarter == 2:
            return dt(today.year,6,30)
        elif quarter == 3:
            return dt(today.year,9,30)
        else:
            return dt(today.year,12,31)

    这个办法虽然笨,但也是相当准确的。哈哈哈!

    展开全文
  • * 根据 年份 和 季度 获取 季度一天季度 最后 一天 * @param year * @param quarter */ function getQuartorStartDate(year,quarter) { let startMonth = 1; if(quarter == 1){ startMonth = 1; }...
    /**
     * 根据 年份 和 季度  获取 季度 第一天 和 季度 最后 一天
     * @param year
     * @param quarter
     */
    function getQuartorStartDate(year,quarter) {
    	let startMonth = 1;
    	if(quarter == 1){
    		startMonth = 1;
    	}else if (quarter == 2){
    		startMonth = 4;
    	}else if (quarter == 3){
    		startMonth = 7;
    	}else if (quarter == 4){
    		startMonth = 10;
    	}
    	let endMonth = startMonth + 2;
    	if (quarter == 0){
    		endMonth = 12
    	}
    	const startDate = year+"-"+formatDate(startMonth)+'-01';
    	const endDate = year + '-' + formatDate(endMonth) + '-' +new Date(year,endMonth,0).getDate()
    	console.log(startDate,endDate)
    	return {startDate,endDate}
    }
    
    //格式化月和日为MM、dd
    function formatDate(value){
    	if(value < 10){
    		value = "0" + value;
    	}
    	return value;
    }
    
    展开全文
  • //获取选中月的第一天和最后一天 function getFirstAndLastMonthDay( year, month){  var firstdate = year + '-' + month + '-01';  var day = new Date(year,month,0);  var lastdate = year + '-' + month + '...
  • 获取季度的第一天和最后一天

    千次阅读 2015-10-13 15:44:53
    //获取季度的第一天 Console.WriteLine(DateTime.Now.AddMonths(0 - ((DateTime.Now.Month - 1) % 3)).ToString(...//获取季度最后一天 Console.WriteLine(DateTime.Parse(DateTime.Now.AddMonths(3 - ((Date
  • 本文主要介绍了setset相关操作及应用,通过获取当前月(季度/年)的最后一天具体事例来解析说明,具有一定的参考价值,下面跟着小编一起来看下吧
  • nterval 参数,具有以下设定值:  设置 描述  Year yy, yyyy 年  quarter qq, q 季  Month mm, m 月 ... Week wk, ww 周的日数  Hour hh 小时  minute mi, n 分钟  second ss, s 秒 ...
  • 主要介绍了c#获取季度时间:季度的第一天、季度最后一天等功能,大家参考使用吧
  • * @Description 根据当前日期获取季度一天 * @param * @Throws * @Return java.util.Date * @Date 2021-08-31 15:37:11 * @Author WangKun **/ public static Date getCurrentQuarterStartTime() { ...
  • year,fiscal_quarter,fiscal_week,date order by fiscal_year,fiscal_quarter,fiscal_week,date ), -- 查询 每周最早的一天 minday as ( select year,quarter,week,min(date) as day from origin group by year,...
  • 获取某月的第一天: select dateadd(month,datediff(month,0,'2009-03-18'),0) 获取本周的第一天: select dateadd(wk,datediff(wk,0,getdate()),0) 获取季度的第一天: ...获取最后一天: ...
  • 以下的SQL语句,均与获取日期中的第一天、最后一天等相关,希望对您有所帮助。 nterval 参数,具有以下设定值:  设置 描述  Year yy, yyyy 年  quarter qq, q 季  Month mm, m 月  dayofyear dy, y ...
  • 获取某年最后一天日期   * @param year 年份   * @return Date   */   public   static   Date getYearLast( int   year){   Calendar calendar = Calendar.getInstance();   calendar.clear()...
  • System.out.println("当前时间所属季度最后一个月最后一天:"+endDate); } /* * @description: 获取当前时间所属季度开始月第一天 * @param: startDate * @return: startDate * @author: zhoushupeng * @...
  • 计算隔天日期,下载五的日期,下个月最后一天的日期,季度最后一天的日期 /** * 计算日期 * @param str1 * @return */ public String getNextRemindTime(String str1) { Date date = new Date(); ...
  • 如上,谁有类似的代码,请教下
  • MySQL里获取当前week、month、quarter的第一天/最后一天 当前week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 1 DAY) from dual 当前week的最后一天: select date_sub(curdate(),...
  • js中获取月份和季度最后一天

    千次阅读 2014-09-11 13:45:19
    //获取选中月的第一天和最后一天 function getFirstAndLastMonthDay( year, month){   var firstdate = year + '-' + month + '-01';  var day = new Date(year,month,0);  var lastdate = year + '-' + ...
  • SQL计算上月最后一天、上季度最后一天、上年最后一天、到季初天数、到年初天数、当前日期是季度中第几个月、当前日期是季度中第几天等 CREATE PROCEDURE sp_sz_tjrq(@startdate char(8), -- 开始日期@years ...
  • Class name Description DateOffset Generic offset class, defaults to 1 calendar day BDay business day (weekday) CDay 这个可以设置特定的假期 Week one week, optionally anchored on ...
  • MySQL获取本年,本月,本周,本季度的第一天和最后一天 -- 返回本周第一天 select date_sub(now(),interval dayofweek(now())-2 day) -- 返回本周最后一天 select date_add(now(),interval 7-dayofweek(now())+1 ...
  • oracle相关时间计算,得到季度第一天、最后一天 ------------------------------------------------ Oracle 日期------------------------------------------ -- 本季度第一天 SELECT to_char(TRUNC(SYSDATE, 'Q'), ...
  • // 季度最后一天时间 value: 0表示本季度,1表示下季度,-1表示上季度 fun getQuarterEndTime(value: Int): Timestamp { val cal = Calendar.getInstance() val currentMonth = cal.get(Calendar.MONTH) + 1 + ...
  • -- 获取当前日期所在季度的第一天 SELECT TRUNC(SYSDATE, 'Q') FROM DUAL; -- 获取指定日期所在季度的第一天 SELECT TRUNC(to_date('202009','yyyyMM'), 'Q') FROM DUAL; -- 获取指定日期所在季度的第一个月 select ...
  • }else if(type==2){//本季度的第一天,最后一天 startTime = getQuarterStartDate(); endTime = getQuarterEndDate(); }else if(type==3){//本年的第一天,最后一天 startTime = y+"-01-01"; endTime = y+"-12-...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 17,470
精华内容 6,988
关键字:

获取季度最后一天