How to select and order with datetime?
My query:
SELECT id, title, note, lastUpdated, dateCreated FROM notes ORDER BY datetime(lastUpdated) DESC
My table:
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
note TEXT,
lastUpdated DATETIME,
dateCreated DATETIME DEFAULT CURRENT_TIMESTAMP)`
My insertion:
INSERT INTO notes (
title, note, lastUpdated)
VALUES (?1,?2,?3)`, [$scope.note.title, $scope.note.note, new Date()]
I insert the date with javascript new Date()
.
If I print the result from this select query:
SELECT id, title, note, lastUpdated, dateCreated FROM notes ORDER BY datetime(lastUpdated) DESC
the result looks something like this:
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'
Try this:
INSERT INTO notes (
title, note, lastUpdated)
VALUES (?1,?2,?3)`, [$scope.note.title, $scope.note.note, new Date().toISOString()]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.