Hi;
the code I'm going to mention below works properly by inserting defined dates :
I insert this second code (to calculate first and last day of the month) in the initial code:
* the first data of date ("2019-03-01") by first_day
* the second data of date ("2019-03-31") by the last_day
the new code becomes like that:
someone can explain to me why this code doesn't work
thanks
the code I'm going to mention below works properly by inserting defined dates :
#!/usr/bin/python3 # -*- coding: utf-8 -*- from tkinter import * from datetime import * import time import calendar import sqlite3 import datetime fen = Tk() fen.title('ILS system ') fen.resizable(0,0) largeur=920 hauteur=660 fen.geometry('{}x{}+0+0'.format(largeur,hauteur)) def monitoring () : fen_monitoring=Toplevel(fen) fen_monitoring.title('ddm axe') fen_monitoring.geometry('450x400+300+150') s= Scrollbar(fen_monitoring) T= Text(fen_monitoring,bg='powder blue',width=450,height=400) s.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) s.config(command=T.yview) T.config(yscrollcommand=s.set) def update_releves(): T.delete('1.0', END) T.update() conn = sqlite3.connect('bdd/test.db') curseur = conn.cursor() for resultats in curseur.execute('SELECT * FROM releves where time_releves_axe_loc35R between "2019-03-01" AND "2019-03-31" ORDER BY time_releves_axe_loc35R DESC'): contenu_table_releves= str(resultats[1])+"\t\t"+ str(resultats[2])+"\t\t"+ str(resultats[3])+"\n" T.insert(END,contenu_table_releves) T.after(1000,update_releves) curseur.close() update_releves() bt=Button(fen,text='click on\nthe button', command=monitoring) bt.pack()this code display to me correctly the content of the database,
I insert this second code (to calculate first and last day of the month) in the initial code:
#to calculate first and last day of the month: now = datetime.datetime.now() start_month = datetime.datetime(now.year, now.month, 1) date_on_next_month = start_month + datetime.timedelta(35) start_next_month = datetime.datetime(date_on_next_month.year, date_on_next_month.month, 1) last_day_month = start_next_month - datetime.timedelta(1) last_day=last_day_month.strftime('%Y-%m-%d') first_day=start_month = datetime.datetime(now.year, now.month, 1).strftime('%Y-%m-%d')and I change at the initial code at the function update_releves:
* the first data of date ("2019-03-01") by first_day
* the second data of date ("2019-03-31") by the last_day
the new code becomes like that:
#!/usr/bin/python3 # -*- coding: utf-8 -*- from tkinter import * from datetime import * import time import calendar import sqlite3 import datetime fen = Tk() fen.title('ILS system ') fen.resizable(0,0) largeur=920 hauteur=660 fen.geometry('{}x{}+0+0'.format(largeur,hauteur)) #to calculate first and last day of the month: now = datetime.datetime.now() start_month = datetime.datetime(now.year, now.month, 1) date_on_next_month = start_month + datetime.timedelta(35) start_next_month = datetime.datetime(date_on_next_month.year, date_on_next_month.month, 1) last_day_month = start_next_month - datetime.timedelta(1) last_day=last_day_month.strftime('%Y-%m-%d') first_day=start_month = datetime.datetime(now.year, now.month, 1).strftime('%Y-%m-%d') def monitoring () : fen_monitoring=Toplevel(fen) fen_monitoring.title('ddm axe') fen_monitoring.geometry('450x400+300+150') s= Scrollbar(fen_monitoring) T= Text(fen_monitoring,bg='powder blue',width=450,height=400) s.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) s.config(command=T.yview) T.config(yscrollcommand=s.set) def update_releves(): T.delete('1.0', END) T.update() global first_day global last_day conn = sqlite3.connect('bdd/test.db') curseur = conn.cursor() for resultats in curseur.execute('SELECT * FROM releves where time_releves_axe_loc35R between first_day AND last_day ORDER BY time_releves_axe_loc35R DESC'): contenu_table_releves= str(resultats[1])+"\t\t"+ str(resultats[2])+"\t\t"+ str(resultats[3])+"\n" T.insert(END,contenu_table_releves) T.after(1000,update_releves) curseur.close() update_releves() bt=Button(fen,text='click on\nthe button', command=monitoring) bt.pack()when I execute this script I have this error: no such column: first_day
someone can explain to me why this code doesn't work
thanks