簡體   English   中英

Cordova Javascript SQLite 按日期時間排序

[英]Cordova Javascript SQLite Order By DateTime

如何 select 和日期時間訂購?

我的查詢:

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 查詢的結果:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM