十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
from datetime import timedelta
from datetime import datetime
c = datetime.datetime(2019, 1, 1, 2, 27, 15, 706351)
int(c.strftime('%W')) # 0, 2019年第0周
c.weekday() # 1, 周2,周一为0
## 数据库查询第几年第几周数据
a = Leak.query.filter(extract('week', Leak.create_time)==10, extract('year', Leak.create_time)==2019).all()
from sqlalchemy import func
Leak.query.with_entities(
func.count(Leak.id),
extract('year', Leak.create_time),
extract('week', Leak.create_time)
).group_by(
extract('year', Leak.create_time),
extract('week', Leak.create_time)
).order_by(
extract('year', Leak.create_time)
).order_by(
extract('week', Leak.create_time)
).all()