stats.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:web 作者: pyjobs 项目源码 文件源码
def get_month_period(period_range):
        """
        return a start date and a end date of x complete previous month
        :param period_range: number of months
        :return: date_from (datetime), date_to (datetime)
        """

        today = datetime.datetime.today().replace(hour=23, minute=59, second=59, microsecond=999999)
        current_month = today.replace(day=1)
        last_day_of_current_month = calendar.monthrange(today.year, today.month)[1]

        if today.day == last_day_of_current_month:
            date_from = current_month + relativedelta(months=-period_range - 1)
            date_to = today
        else:
            date_from = current_month + relativedelta(months=-period_range)
            date_to = current_month - datetime.timedelta(days=1)

        return date_from, date_to
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号