sqlite刪除與當前時間差值在10秒以上的記錄

2021-07-12 05:59:41 字數 2289 閱讀 3729

sqlite> delete    from   test1  where julianday('now')*86400 -julianday(a_date)*

86400>10;

sqlite的最小時間差的單位是天,當然是小數型別的,不是整型的,所以可以乘以86400(=24*3600)來計算相差的秒數

sqlite> select   julianday('2016-05-31') - julianday('2016-06-01');

-1.0

sqlite> select julianday('2016-05-31') - julianday('2016-06-02');

-2.0

sqlite> select julianday('2016-06-11') - julianday('2016-06-02');

9.0sqlite> select julianday('2016-06-01 13:00:00') - julianday('2016-06-01 12:00:

00');

0.0416666665114462

sqlite> select julianday('2016-06-01 12:00:20') - julianday('2016-06-01 12:00:

00');

0.000231481622904539

sqlite> select * from test1 order by a_date;

2016-04-23 17:43:35

2016-04-31 17:40:35

2016-05-26 19:40:35

2016-05-29 19:40:35

2016-05-30 19:40:35

2016-05-31 17:30:00

2016-05-31 17:30:01

2016-05-31 17:30:02

2016-05-31 17:30:03

2016-05-31 17:30:05

2016-05-31 17:30:15

2016-05-31 17:30:35

2016-05-31 17:40:35

2016-05-31 17:40:35

2016-05-31 19:40:35

2016-06-01 19:40:35

2016-12-01 19:40:35

sqlite> select * from test1 where julianday('now') -julianday(a_date)>1;

2016-05-26 19:40:35

2016-05-29 19:40:35

2016-04-31 17:40:35

2016-04-23 17:43:35

sqlite> select * from test1 where julianday('now')*86400 -julianday(a_date)

*86400>10;

2016-05-30 19:40:35

2016-05-26 19:40:35

2016-05-29 19:40:35

2016-04-31 17:40:35

2016-04-23 17:43:35

sqlite> delete from test1 where julianday('now')*86400 -julianday(a_date)*

86400>10;

sqlite> select * from test1 order by a_date;

2016-05-31 17:30:00

2016-05-31 17:30:01

2016-05-31 17:30:02

2016-05-31 17:30:03

2016-05-31 17:30:05

2016-05-31 17:30:15

2016-05-31 17:30:35

2016-05-31 17:40:35

2016-05-31 17:40:35

2016-05-31 19:40:35

2016-06-01 19:40:35

2016-12-01 19:40:35

sqlite>

sqlite> create  table   test1(a_date date);
這是建表語句

有一點很重要:在真機上測試,無法這樣刪除記錄!!!!!!!!!

Sqlite 當前時區的當前時間

想得到乙個符合本機區域設定的當前時間,必須用date函式來轉換,但date只函式只返回當前日期,而我需要的是返回當前日期及時間,所以這裡把它換成datetime函式,即 datetime current timestamp,localtime 以下是sqlite下測試的輸出資訊 sqlite sel...

C 日期 時間 獲取當前時間 計算時間差

include include intmain 執行結果 18 18 342020 請按任意鍵繼續.include include using namespace std intmain double seconds t2.tm year 2020 1900 t2.tm mon 8 t2.tm md...

根據Long值求與當前系統時間的時間差

先上 public class timeutil return result 在一開始,我認為求兩個long值之間的時間差是很容易。也沒想那麼多,之前計算兩個時間點之間天數的公式是這麼寫的 int day int millis 1000 time 3600 24 但是這麼寫就會出現乙個問題 它會按照...