I’m having some trouble working with dates on my Android application that uses SQLite.
I have a couple questions:
- What type should I use to store dates in SQLite (text, integer, …)?
- Given the best way to store dates how do I store It properly using ContentValues?
- What’s the best way to retrieve the date from the SQLite database?
- How to make a sql select on SQLite, ordering the results by date?
You can use a text field to store dates within
SQLite.Storing dates in UTC format, the default if you use
datetime('now')(yyyy-MM-dd HH:mm:ss)will then allow sorting by the date column.Retrieving dates as strings from
SQLiteyou can then format/convert them as required into local regionalised formats using the Calendar or theandroid.text.format.DateUtils.formatDateTimemethod.Here’s a regionalised formatter method I use;