如何在 sqlite 中从日期时间中绕过减号和秒?
喜欢:
time_round(2023-10-02 23:52:51, '秒') = 2023-10-02 23:52:00
time_round(2023-10-02 23:02:01, '秒') = 2023-10-02 23:02:00
time_round(2023-10-02 23:02:01, '分钟') = 2023-10-02 23:00:00
这是一种方法的演示:-
DROP TABLE IF EXISTS a_table;
CREATE TABLE IF NOT EXISTS a_table (time TEXT DEFAULT CUURENT_TIMESTAMP);
WITH counter(x) AS (SELECT 1 UNION ALL SELECT x + 1 FROM counter LIMIT 10)
INSERT INTO a_table SELECT datetime('now',(random() % 1234)||' seconds') FROM counter;
/* The query (see the expression used for the `roundedTime` column)
SELECT *,
datetime(
time,
'-'||strftime('%M',time)||' minutes',
'-'||strftime('%S',time)||' seconds'
) AS roundedTime,
strftime('%M',time) AS mins,
strftime('%S',time) AS secs
FROM a_table;
DROP TABLE IF EXISTS a_table;
运行时,输出将类似于:-