Skip to content Skip to sidebar Skip to footer

Android Sqlite Inserting And Ordering By Time

I am writing an Android app that allows the user to add a new Module to the database and add the day, starttime, finish time and room for that module. The user is able to view all

Solution 1:

It looks like you're using strings for your timestamps. You need to use an integer to actually store a unix timestamp. Then your queries will using ORDER BY will sort correctly, ex:

SELECT*FROMtableWHERE .... ORDERBY updateTime

I'd suggest converting the string to an integer using straight Java, since that allows you to use those parameterized inserts like you showed in your example. However, you could manually write the queries and use the time functions provided by SQLite:

http://www.sqlite.org/lang_datefunc.html


Edit:

It appears you can use a string timestamp with SQLite, but only a few formats are supported (that page has examples.) I'm not sure that works in Android though, I've always used integer field types for times (which can actually store Java longs.)

-- Dan

Post a Comment for "Android Sqlite Inserting And Ordering By Time"