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)"
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)"
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());
Try Like this:
/* Creating Table */
String query = "CREATE TABLE " + TABLE_ORDER_DETAILS
+ "("
+ OD_LOCAL_TIME + " TEXT,"
+ OD_SERVER_TIME + " TEXT "
+ ")";
db.execSQL(query);