user555910
user555910

Reputation: 2667

how to store a time value in SQLite database in Android?

I want to store a timevalue in an SQLite database in Android. My time value is in EditText, and when I click the save button I would like the time value to be stored in the database. And also I want to review the already-stored value in the database.

Upvotes: 8

Views: 19128

Answers (2)

f20k
f20k

Reputation: 3106

Sqlite + timestamp = Date and time functions

Sqlite + timestamp + android = Timestamp Class

Other options

  • create a column for each piece of info you wish to store (day, hour, min, second, etc)
  • convert time into long and store that instead. Use java.sql.Time

Upvotes: 3

Jon Colverson
Jon Colverson

Reputation: 3066

SQLite doesn't have a specific datatype for storing times, and leaves it up to you whether you want to store them as text, integers, or floating-point values, so you can establish whatever convention works best for you.

For your application where you want the time to be editable by the user I'd suggest looking into the DatePicker and TimePicker widgets, so that you don't have to worry about parsing and formatting the time as text, and then the Java Calendar class for converting the data from those into a simple value that you can put in the database (I'd suggest using the getTimeInMillis() method to convert it into a integer).

Upvotes: 6

Related Questions