1

I need to store dates in my app database and i need to know if is possible to create a table with a date type column in Android Sqlite like this:

"CREATE TABLE example1 (ex_id INTEGER PRIMARY KEY, ex_date DATE)"
Pierre-Luc Pineault
  • 8,993
  • 6
  • 40
  • 55
user3065901
  • 4,678
  • 11
  • 30
  • 52

2 Answers2

4

No it is not.

But you can use Date.getTime(), to have the timestamp (long in JAVA, INTEGER in SQLite), to be able to store and retrieve the date.

To retrieve the date from database, you will do :

new Date(cursor.getLong(yourColumnIndex));

And to store it :

contentValues.put("yourDateColumn", date.getTime());
0

Try Like this:

/* Creating Table */
String query = "CREATE TABLE " + TABLE_ORDER_DETAILS
+ "("
+ OD_LOCAL_TIME + " TEXT,"
+ OD_SERVER_TIME + " TEXT "
+ ")";

db.execSQL(query);
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437