DougieLawson wrote:If you're storing date and/or time values you should use a timestamp column. That will order by correctly.
Thank you, I've changed the structure of the fields time and date
time = time
date = date
But i will have to make some change to my Python code, to write a correct date en time stamp
i've got an error now
time is stored correctly but the date is 0000-00-00
I think i have to change the format of the date, now i use
Code: Select all
import Adafruit_DHT as dht
import MySQLdb
import time
conn = MySQLdb.connect(host="localhost", user="xxxx", passwd="xxxx", db="RASPDB")
curs=conn.cursor()
timenow = time.strftime('%X')
datenow = time.strftime('%x')
h,t = dht.read_retry(dht.DHT22, 26)
#print 'Temp={0:0.1f}C Humidity={1:0.1f}%'.format(t, h)
#print 'Temp={0:0.1f}C'.format(t, h)
#print 'Humidity={1:0.1f}%'.format(t, h)
#print t
#print h
var_temp = '{0:0.1f}'.format(t, h)
var_humd = '{1:0.1f}'.format(t, h)
#print datenow
#print timenow
#print var_temp
#print var_humd
curs.execute ("""INSERT INTO value VALUES(%s, %s, %s, %s)""", (datenow,timenow,var_temp,var_humd))
conn.commit()
#curs.execute ("""SELECT * FROM value;""")
#result = curs.fetchall()
#print result
curs.close()
conn.close()