For example, I have a Sqlite3 type database created with SQLite Studio, and a table structure with table name Statisticsdata is:
--table: StatisticsdataCREATE TABLE"Statisticsdata" ("Id" )TEXT not NULL, "MachineName"NVARCHAR, "SessionId"INTEGER, "ProcessId"INTEGER, "ProcessName"NVARCHAR, "Processrunningstatus"NVARCHAR, "Workingsetmemory"NVARCHAR, "Workingsetprivatememory"NVARCHAR, "Workingsetpeak"NVARCHAR, "ThreadCount"NVARCHAR, "Handlecount"NVARCHAR, "Totalprocessortime"NVARCHAR, "Userprocessortime"NVARCHAR, "Privilegedprocessortime"NVARCHAR, "StartTime"DATETIME, "Exittime"DATETIME, "Domain"NVARCHAR, "UserName"NVARCHAR, "FileName"NVARCHAR, "Arguments"NVARCHAR, "WorkingDirectory"NVARCHAR, "createdtime"DATETIME,PRIMARY KEY("Id"ASC),CONSTRAINT"PK_ID"UNIQUE("Id"ASC))
Example:
Today is 2017-08-10, to delete data 7 days ago, that is to say, all less than equals 2017-08-03 will be deleted.
notation 1: ignore the time precision, directly compare the date, delete the data n days ago.
DELETE from WHERE Date ('now'– 7day'>= date (createdtime);
Figure 2: Calculate the time precision, compare the date and time, delete the data from N days ago.
DELETE from WHERE julianday ('now'->=7;
Official tutorials on time operations and comparison functions: http://www.sqlite.org/lang_datefunc.html
Translated from the official website of the Chinese reference: http://www.cnblogs.com/ygm900/p/4460644.html
The time difference judgment of SQLite--two ways to delete data from N days ago