我不知道如何访问存储在varchar类型列中的日期时间字符串 我的烧瓶方法如下,从我执行mysql查询的地方开始
@app.route("/canopus_cycle", methods=['GET','POST'])
@is_logged_in
@is_attendence
@not_admin_logged_in
def canopus_cycles():
if session['cycles'] == '1':
import datetime as DT
from datetime import datetime as dt
today = DT.date.today()
month = today - DT.timedelta(days=30)
print("today = ", today)
print("month = ", month)
month = dt.strftime(month, "%Y-%m-%d %H:%M:%S")
today = dt.strftime(today, "%Y-%m-%d %H:%M:%S")
print("strf today = ", today)
print("strf month = ", month)
cur99 = connn2.cursor(dictionary=True)
query = "SELECT * FROM custom_duty_mail WHERE STR_TO_DATE(add_time, '%Y-%m-%d %H:%i:%s') BETWEEN STR_TO_DATE('"+str(month)+"', '%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('"+str(today)+"', '%Y-%m-%d %H:%i:%s')"
print("query = ", query)
cur99.execute(query)
data2 = cur99.fetchall()
print("data = ", data2)
else:
flash("SORRY YOU ARE NOT ALLOWED TO SEE THIS PAGE","danger")
return redirect(url_for('dashboard'))
return render_template('canopus_cycle.html', data2=data2)
我不知道我在查询中做什么错 我将空设置为输出 下面是我的输出屏幕
today = 2019-06-24
month = 2019-05-25
strf today = 2019-06-24 00:00:00
strf month = 2019-05-25 00:00:00
query = SELECT * FROM custom_duty_mail WHERE STR_TO_DATE(add_time, '%Y-%m-%d %H:%i:%s') BETWEEN STR_TO_DATE('2019-05-25 00:00:00', '%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('2019-06-24 00:00:00', '%Y-%m-%d %H:%i:%s')
data = []
请指出一点 以下是我对表格的描述
mysql> describe custom_duty_mail;
+-------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------+------+-----+---------+-------+
| mode | varchar(100) | NO | | NULL | |
| inwd | varchar(100) | NO | | NULL | |
| etamail | varchar(100) | NO | | NULL | |
| inwdmail | varchar(100) | NO | | NULL | |
| add_time | varchar(200) | YES | | NULL | |
+-------------------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)