In SQLite Order By Datetime desc returns invalid data

I have one doubt about Sqlite.dteTime DataType - Varchar (200) in table structure. I want to get the result in date order.

"select dteTime from table ORDER BY dteTime Desc",

result of receiving

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

"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:51:25 AM"

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

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

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

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

Instead, how can I get (expected output)

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

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

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

"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 12:38:43 AM"

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

Any solution?

+3


source to share


2 answers


Use a date format such as unixtime (seconds / milliseconds since epoch) or ISO 8601 (for example yyyy-MM-dd'T'HH:mm:ssZ

) for your date and time stamps so that the natural sort order is chronological as well.



+2


source


SQLite has no internal date type. It is sorted alphabetically in such a case. You can write your dates in iso format or convert them to do sorting.



+1


source







All Articles