热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在SQLiteOrderByDatetime中,desc返回错误的数据-InSQLiteOrderByDatetimedescreturningwrongdata

IhaveonedoubtinSqlite.dteTimeDataTypeisVarchar(200)inTablestructure.Iwanttogetresult

I have one doubt in Sqlite.dteTime DataType is Varchar(200) in Table structure. I want to get result in order by Date Time.

我在Sqlite.dteTime中有一个疑问DataType是Table结构中的Varchar(200)。我希望按日期时间顺序获得结果。

"select dteTime from table ORDER BY dteTime Desc",

“从表ORDER BY dteTime Desc中选择dteTime”,

getting result is

得到的结果是

"05/05/2015 12:38:43 PM"

“05/05/2015 12:38:43 PM”

"05/05/2015 12:38:43 AM"

“05/05/2015 12:38:43 AM”

"05/05/2015 10:57:04 AM"

“05/05/2015 10:57:04 AM”

"05/05/2015 10:57:04 AM"

“05/05/2015 10:57:04 AM”

"05/05/2015 10:51:25 AM"

“05/05/2015 10:51:25 AM”

"05/05/2015 10:51:25 AM"

“05/05/2015 10:51:25 AM”

"05/05/2015 04:38:35 PM"

“05/05/2015 04:38:35 PM”

"05/05/2015 04:00:48 PM"

“05/05/2015 04:00:48 PM”

"05/04/2015 11:38:43 PM"

“05/04/2015 11:38:43 PM”

Instead of this how can i get(Expected Result)

而不是这个我怎么能得到(预期结果)

"05/05/2015 04:38:35 PM"

“05/05/2015 04:38:35 PM”

"05/05/2015 04:00:48 PM"

“05/05/2015 04:00:48 PM”

"05/05/2015 12:38:43 PM"

“05/05/2015 12:38:43 PM”

"05/05/2015 10:57:04 AM"

“05/05/2015 10:57:04 AM”

"05/05/2015 10:57:04 AM"

“05/05/2015 10:57:04 AM”

"05/05/2015 10:51:25 AM"

“05/05/2015 10:51:25 AM”

"05/05/2015 10:51:25 AM"

“05/05/2015 10:51:25 AM”

"05/05/2015 12:38:43 AM"

“05/05/2015 12:38:43 AM”

"05/04/2015 11:38:43 PM"

“05/04/2015 11:38:43 PM”

Any solution?

2 个解决方案

#1


Use a date format such as unixtime (seconds/milliseconds since an epoch) or ISO 8601 (e.g. yyyy-MM-dd'T'HH:mm:ssZ) for your datetime stamps so that the natural sort order is also the chronological order.

使用日期格式,例如unixtime(自纪元以来的秒/毫秒)或ISO 8601(例如yyyy-MM-dd'T'HH:mm:ssZ)作为日期时间戳,以便自然排序顺序也是按时间顺序排列。

#2


SQLite doesn't have an internal date type. It's sorting alphabetically in a case like this. You can write your dates in an iso format or transform them to do the sort.

SQLite没有内部日期类型。在这种情况下,它按字母顺序排序。您可以用iso格式编写日期或转换它们以进行排序。


推荐阅读
author-avatar
e絕纞乄
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有