开发者

How to convert TEXT data to DATE TIME in SQLITE in Android?

I am new to android. I am using a database to store my data. I also store date as TEXT in database. format of date is as follow... "Mon, 20 Oct 2010 12:30:00" So i stored them in TEXT datatype not in DateTime. Now i want to display them in following format "Mon, 20 Oct 2010" The main thing is that i want to ORDER them in DESC. I write a query for this but it dose not work. It there is some alternative for this???? i also read about "strftime()" function of SQLITE but i did not know how to use it for this.

My Query is:

"Cursor c = myDB.rawQuery("Select 开发者_运维百科* from List ORDER BY to_date(substr(date,6,20), 'DD-MM-YYYYTHH24:MI:SS') DESC",null);"

Please Help me... Thanks in advance!


I'd recommend you to store your DateTime values as INTEGER using Date.getTime() (milliseconds since Jan. 1, 1970, midnight GMT). So you can use ASC and DESC operators without conversions which will require less resources.


Finally i store date as text format and then after retrieve i sort date by sending my text(date) value to the constructor of Date class. And the using that object i sort them and adjust items related to that dated in proper location by Insertion Sort logic. :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜