"Python 3.19"? SQLite doesn't have a set datetime record format. It's up to you to standardize the input. There're some built-in functions to help out, but you have to format it yourself. If you're doing them as standardized strings, ('2016-10-21 15:40:14') then when you're retrieving them from the database you can run the resulting string through strptime to get a Python datetime. And when you're inserting or comparing from a Python datetime, you should use strftime on the Python datetime to turn it into the appropriate string before passing it to SQLite, as it will do a textual comparison against the other text entries in there.
-----Original Message----- From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of Rick Kohrs Sent: Friday, October 21, 2016 3:05 PM To: sqlite-users@mailinglists.sqlite.org Subject: [sqlite] Troubles matching variable as type TIMESTAMP Using Python 3.19. I am reading in a lines from an ever growing log file. Values from each line of the log file are parsed and placed into a database. Each record has a variable of type TIMESTAMP. Multiple records have the same the same value for time stamp. After a line is processed, I need to check if there are multiple records with the same time stamp and count the total number of records returned. I'm struggling trying to create a select clause to match a variable of type TIMESTAMP. Example Record (datetime.datetime(2016, 10, 13, 8, 10), u'HS_H08_20161013_0810_B09_JP03_R20_S0101.DAT', u'Himawari8', 2016, 10, 13, 8, 10, 9, u'Japan', -1, 3, u'test') Code snipits: #HS_H08_20161013_0000_B01_R304_R10_S0101.DAT imageInfo['year'] = int(filenameVals[2][0:4]) imageInfo['month'] = int(filenameVals[2][4:6]) imageInfo['day'] = int(filenameVals[2][6:8]) imageInfo['hour'] = int(filenameVals[3][0:2]) imageInfo['minute'] = int(filenameVals[3][2:4]) imageInfo['band'] = int(filenameVals[4][2:4]) string_date = (str(imageInfo['year']) + '-' + str(imageInfo['month']) + '-' + str(imageInfo['day']) + ' ' + str(imageInfo['hour']) + ':' + str(imageInfo['minute']) + ':00.0') imageInfo['dateTime'] = datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f") ....... sqlCommand = """ CREATE TABLE himawari_db ( date_time TIMESTAMP, ........ checkTime = imageInfo['dateTime'] print(checkTime) try: satDB.execute("SELECT * FROM himawari_db WHERE date_time=? ",(checkTime,)) _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users