python flask 时间处理 filter多条件组装 当前月1号 当前月内 3个月内 当日内

     filter = []
        filter.append(PayLog.objectid == current_user['id'])
        filter.append(PayLog.type == current_app.config['PAY_USETYPE_APPLY_MONEY'])

        if info['unit'] == 1:
            dateC = datetime.date.today().replace(day=1)
            start = int(time.mktime(dateC.timetuple()))
            endC = dateC + relativedelta(months=+1)
            end = int(time.mktime(endC.timetuple()))
            filter.append(PayLog.createtime < end)
            filter.append(PayLog.createtime >= start)
        elif info['unit'] == 2:
            dateC = datetime.date.today()
            start = int(time.mktime(dateC.timetuple()))
            endC = dateC + relativedelta(days=+1)
            end = int(time.mktime(endC.timetuple()))
            filter.append(PayLog.createtime < end)
            filter.append(PayLog.createtime >= start)
        elif info['unit'] == 3:
            dateC = datetime.date.today().replace(day=1)
            sdateC = dateC + relativedelta(months=-3)
            start = int(time.mktime(sdateC.timetuple()))
            endC = dateC + relativedelta(months=+1)
            end = int(time.mktime(endC.timetuple()))
            filter.append(PayLog.createtime < end)
            filter.append(PayLog.createtime >= start)
        count = PayLog.query.filter(*filter).count()

  

posted @ 2020-08-27 14:47  jackduan1  阅读(390)  评论(0编辑  收藏  举报