python查询mysql表名字动态日期,用python实现数据库中日期间的查询

我不可能在2019:00开发一个查询,但我不能用一个日期和日期之间插入一个查询和一个查询。我想从用户那里得到日期。如果真的很简单,我很抱歉

我在网上搜索,尝试了不同的符号,但我无法解决这个问题import pyodbc

from tkinter import *

import datetime

root = Tk()

root.configure(background='blanched almond')

root.geometry("700x600")

root.title("QUERY PROGRAM ")

label1= Label(root,text=" QUERY PROGRAM ",bg='blanched almond',fg='LightSkyBlue4',font="Arial 12 bold")

label1.pack()

label2=Label(root,text="Please enter the first date such as 2019-05-22 00:00:00",bg='blanched almond')

label2.place(x=0,y=100)

label3=Label(root,text="Please enter the last date such as 2019-05-24 00:00:00",bg='blanched almond')

label3.place(x=0,y=160)

date1_text=StringVar()

date2_text=StringVar()

entry1=Entry(root, textvariable=date1_text)

entry1.place(x=10,y=130)

entry2=Entry(root, textvariable=date2_text)

entry2.place(x=10,y=190)

date1=date1_text.get()

date2=date2_text.get()

def query():

con= pyodbc.connect("DRIVER={SQL Server}; server=server;database=TestVT;uid=da;pwd=1234")

cur = con.cursor()

cur.execute("select date from TestVT.data where date >='%s' and date < '%s' and datetype in (4,5,6,7,13)" %(date1,date2))

data =cur .fetchall()

for i in data:

#print (f" ID = {i[0]} NAME={i[1]}")

print (i)

cur.close()

con.close()

button1=Button(root,text="QUERY",command=query )

button1.place(x=300,y=280)

root.mainloop()

ıf i remove“from%s like where date&gt;=%s,则在关键字“and”附近收到语法不正确的消息。谢谢你的努力

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值