【发布时间】:2020-05-21 10:50:42
【问题描述】:
我有一些数据存储在数据库中,我正在通过烧瓶和烧瓶-sqlalchemy 访问和过滤这些数据。
我正在尝试根据start 和end 日期过滤数据,这些日期将作为来自网址中request.args.get() 的用户输入。在数据库中,数据为"2020-05-12T00:00:00+02:00" 格式,当用户输入日期时,他将只输入日期而不是时间或时区(例如:2020-05-12)。因此,根据用户为start 和end(包括end)输入的值,我想比较日期并返回值。但是,返回的值必须具有原始日期格式
数据如下:
{
"items": [
{
"id": 1,
"value": 21.4,
"start": "2020-05-12T00:00:00+02:00",
"end": "2020-05-12T01:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 2,
"value": 18.93,
"start": "2020-05-12T01:00:00+02:00",
"end": "2020-05-12T02:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 3,
"value": 18.06,
"start": "2020-05-13T02:00:00+02:00",
"end": "2020-05-13T03:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 4,
"value": 17.05,
"start": "2020-05-13T03:00:00+02:00",
"end": "2020-05-13T04:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 5,
"value": 16.84,
"start": "2020-05-14T04:00:00+02:00",
"end": "2020-05-14T05:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 6,
"value": 19.3,
"start": "2020-05-14T05:00:00+02:00",
"end": "2020-05-14T06:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
}]}
示例:
如果:
start 是2020-05-12 & end 是2020-05-14,从以上数据来看,必须返回以下数据:
{
"items": [
{
"id": 1,
"value": 21.4,
"start": "2020-05-12T00:00:00+02:00",
"end": "2020-05-12T01:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 2,
"value": 18.93,
"start": "2020-05-12T01:00:00+02:00",
"end": "2020-05-12T02:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 3,
"value": 18.06,
"start": "2020-05-13T02:00:00+02:00",
"end": "2020-05-13T03:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 4,
"value": 17.05,
"start": "2020-05-13T03:00:00+02:00",
"end": "2020-05-13T04:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
},
{
"id": 5,
"value": 16.84,
"start": "2020-05-14T04:00:00+02:00",
"end": "2020-05-14T05:00:00+02:00",
"country_code": "DE",
"price_type": "DAY_AHEAD"
}]}
【问题讨论】:
标签: python python-3.x datetime flask flask-sqlalchemy