如何选择和订购日期时间?
我的查询:
SELECT id, title, note, lastUpdated, dateCreated FROM notes ORDER BY datetime(lastUpdated) DESC
我的桌子:
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
note TEXT,
lastUpdated DATETIME,
dateCreated DATETIME DEFAULT CURRENT_TIMESTAMP)`
我的插入:
INSERT INTO notes (
title, note, lastUpdated)
VALUES (?1,?2,?3)`, [$scope.note.title, $scope.note.note, new Date()]
我使用 javascript new Date()
插入日期。
如果我打印这个选择查询的结果:
SELECT id, title, note, lastUpdated, dateCreated FROM notes ORDER BY datetime(lastUpdated) DESC
结果看起来像这样:
dateCreated:'2021-01-17 09:24:13'
id:1
lastUpdated:'Mon Jan 18 2021 00:37:36 GMT-0700 (Mountain Standard Time)'
note:'Test'
title:'Title'
答案 0 :(得分:1)
试试这个:
INSERT INTO notes (
title, note, lastUpdated)
VALUES (?1,?2,?3)`, [$scope.note.title, $scope.note.note, new Date().toISOString()]