# -*- coding:utf-8 -*-
import time,datetime
import pymysql
# print datetime.datetime.strftime(time.time(),"%Y-%m-%d %H:%M")
# Ti= time.strftime("%Y-%m-%d")
# Ti2 = '2018-03-09'
T1=datetime.datetime.now().strftime('%Y-%m-%d ')
T2 = (datetime.datetime.now()-datetime.timedelta(days=10)).strftime('%Y-%m-%d ')
T3 = (datetime.datetime.now()-datetime.timedelta(days=2)).strftime('%Y-%m-%d ')
T4 = (datetime.datetime.now()-datetime.timedelta(days=3)).strftime('%Y-%m-%d ')
T5 = (datetime.datetime.now()-datetime.timedelta(days=4)).strftime('%Y-%m-%d ')
# a=str([x for x in range(0,4)]).replace('[','').replace(']','')
# a='{}{}{}{}{}'.format(0,1,2,5,8)
# Ti= time.strftime("%Y-%m-%d")
# Ti=datetime.datetime.strftime(time.time(),"%Y-%m-%d %H:%M")
根据数据库中存表时间读取信息
def select_sql():
conn = pymysql.connect(host='127.0.0.1',user='root',passwd='mysql',database='database_name',port =3306,charset="utf8")
cs=conn.cursor()
# conut = cs.execute(""" select * from table_name where insert_time = '%s'"""%Ti)
# conut = cs.execute(""" select * from table_name where insert_time like '{}%'""".format(Ti))
conut = cs.execute(""" select * from table_name where insert_time like '{}%' or insert_time like '{}%'""".format(T3,T2))
# concent=cs.fetchall()
cs.close()
conn.close()
return conut
print select_sql(),T3,T2
# print Ti,a
# print nowTime,afterTomorrowTime,afteTomorrowTime