直接把数据库查询的查询结果中的某个字段转为集合
daily_cursor = DB_CONN.daily.find(
{'code': 'xxxx', 'date': {'$gte': begin_date, '$lte': end_date}, 'index': True},
sort=[('date', ASCENDING)],
projection={'date': True, '_id': False})
dates = [x['date'] for x in daily_cursor]
计算前N天的日期
begin_date = (datetime.now() - timedelta(days=1)).strftime('%Y%m%d')
begin_date2 = (datetime.now() - timedelta(days=2)).strftime('%Y-%m-%d')
print(begin_date)
print(begin_date2)
结果:
20210624
2021-06-23
网友评论