zafrada
zafrada

Reputation: 61

Delete records of a certain date in sqlite?

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 this is not working. am i missing something here?

thanks a lot in advance.

Upvotes: 4

Views: 9201

Answers (2)

Mark
Mark

Reputation: 11

Use the Date function to extract and compare just the date:

DELETE FROM sessions WHERE DATE(timestamp) = '2010-12-06'

Upvotes: 1

Duder
Duder

Reputation: 81

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.

Upvotes: 8

Related Questions