1

I'm using a function inside a python program that doesn't work as expected. I would like to call a sqlite3 function that give me the last record registrered every 2 seconds It works fine until midnight, then it continues reading the valuew of the same day, it doesn't change when a new day arrives.

the function is(data is today, ora is actual hour):

import sqlite3 from sqlite3 import Error import time

def leggi_tmp():

try:
    time.sleep(2)
    conn = sqlite3.connect('DB.db')
    cursor = conn.cursor()
    cursor.execute('''SELECT * FROM tmp_hr WHERE data = date('now') ORDER BY ora DESC LIMIT 1''')

    #Fetching 1st row from the table
    result = cursor.fetchone()
    tmpe = result[0]
    print(result)

    #Closing the connection
    conn.close()
except Error as e:
    print(e)
return tmpe

when I do:

while data.tm_hour in fase_1 and func2_letture.leggi_tmp() <= temp_min_giorno :

func2_letture.leggi_tmp() only reads the day when it is called the first time(but works as expected during the day), it doesn't read the new date when new day arrives

I can't understand where my mistake is...

1 Answer 1

0

I suspect that this is a timezone problem.
Add the 'localtime' modifier to the function date():

WHERE data = date('now', 'localtime')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.