Cordova Javascript SQLite Order By DateTime



如何使用datetime进行选择和排序?

我查询:

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()]

我用javascriptnew Date()插入日期。

如果我打印这个select查询的结果:

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'

试试这个:

INSERT INTO notes (
title, note, lastUpdated) 
VALUES (?1,?2,?3)`, [$scope.note.title, $scope.note.note, new Date().toISOString()]

最新更新