I have a table with a column named timestamp
timestamp DATE DEFAULT (datetime('now','localtime'))
which stores records in the table like this:
2010-12-06 18:41:37
How can I delete records of a certain date? I'm using:
DELETE FROM sessions WHERE timestamp = '2010-12-06';
but开发者_如何学JAVA this is not working. am i missing something here?
thanks a lot in advance.
DELETE FROM sessions WHERE timestamp = '2010-12-06'
is basically selecting and deleting any records timestamped as '2010-12-06 00:00:00'
You would be better off defining a range:
DELETE FROM sessions WHERE timestamp >= '2010-12-06' AND timestamp < '2010-12-07'
will delete any sessions that fell in that range.
Use the Date function to extract and compare just the date:
DELETE FROM sessions WHERE DATE(timestamp) = '2010-12-06'
精彩评论