从具有不同格式的烧瓶形式的日期中提取月份
Extracting month from date in flaskform with different format
我正在尝试创建一个由月份和计数组成的代码。计数很简单,但我不明白如何从日期格式中提取月份。
型号:
req_date =db.Column(db.Date, nullable=False, default=date.today())
req_code =db.Column(db.String, nullable=False, unique=True)
表格:
reqdate = DateField('Request Date')
路线:
currentyear = extract('year',form.reqdate.data)
currentmonth= extract('month', form.reqdate.data)
ronum = 'RO-'+'/'+str(currentmonth)+'/'+str(currentyear)
我尝试将此功能用于我之前找到的路线,但它似乎不起作用。
我得到的不是 RO-/01/2021
。我收到此错误:
RO-/EXTRACT(month FROM :param_1)/EXTRACT(year FROM :param_1)
有谁知道提取它的函数吗?或者如果功能没有错,我哪里错了?
DateField
returns 一个 datetime.date
对象
这意味着您应该能够做到:
# Data from the form which has been formatted to datetime.date object
current_date = form.reqdate.data
current_year = current_date.year
current_month = current_date.month
可以找到 datetime.date
上可用的属性 here
我正在尝试创建一个由月份和计数组成的代码。计数很简单,但我不明白如何从日期格式中提取月份。
型号:
req_date =db.Column(db.Date, nullable=False, default=date.today())
req_code =db.Column(db.String, nullable=False, unique=True)
表格:
reqdate = DateField('Request Date')
路线:
currentyear = extract('year',form.reqdate.data)
currentmonth= extract('month', form.reqdate.data)
ronum = 'RO-'+'/'+str(currentmonth)+'/'+str(currentyear)
我尝试将此功能用于我之前找到的路线,但它似乎不起作用。
我得到的不是 RO-/01/2021
。我收到此错误:
RO-/EXTRACT(month FROM :param_1)/EXTRACT(year FROM :param_1)
有谁知道提取它的函数吗?或者如果功能没有错,我哪里错了?
DateField
returns 一个 datetime.date
对象
这意味着您应该能够做到:
# Data from the form which has been formatted to datetime.date object
current_date = form.reqdate.data
current_year = current_date.year
current_month = current_date.month
可以找到 datetime.date
上可用的属性 here