简体   繁体   English

Cordova Javascript SQLite 按日期时间排序

[英]Cordova Javascript SQLite Order By DateTime

How to select and order with datetime?如何 select 和日期时间订购?

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() .我用 javascript new Date()插入日期。

If I print the result from this select query:如果我打印此 select 查询的结果:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM