How to insert a proper date value using SQLiteDatabase.update/SQLiteDatabase.insert
.
The problem appears to be that ContentValues takes only Strings as input of its pairs.
There is a solution here
For quick reference, this is the solution provided in that question:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
ContentValues initialValues = new ContentValues();
initialValues.put("date_created", dateFormat.format(date));
long rowId = mDb.insert(DATABASE_TABLE, null, initialValues);
The problem with this solution is, it doesnot insert a proper 'Date' value into a Date column, but inserts the DAte as a text. I know this because when i retrieve the data (select) and do date operations on it, it doen't work.
(TO be precise, datetime(DATE_COLUMN,'localtime')
returns null value)
Can someone help me with my problem? I have already wasted hours :(