开发者

Android SQLite problem

I have stored date as primary key in SQLite database (MM/DD/YYYY format) when I select date in DESC order, it is not selecting in correct order i.e. in place of

26NOV2010

25NOV2010

26NOV2009

25NOV2009

it is printing like that

26NOV2010

26NOV2009

25NOV2010

25NOV2009

plz provide some pointer for storing date in correct 开发者_开发问答format and retrieving in descending order.

thanking you


SQLite treats your dates as strings, simply sorting them as it would sort strings. SQLite does not have a specific data type for DATE. You need to store your date values in line with SQLite's date / time functions.

From the SQLite documentation: SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

* TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
* REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
* INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. 

Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

See Datatypes In SQLite Version 3 and Date And Time Functions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜