开发者

Delete records of a certain date in sqlite?

开发者 https://www.devze.com 2023-01-28 23:20 出处:网络
I have a table with a column named timestamp timestamp DATE DEFAULT (datetime(\'now\',\'localtime\')) which stores records in the table like this:

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'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号