I want to insert current date in SQLite database datetime type field. How can I do this?
UPDATE : Using mDb.execSQL("INSERT INTO " + DATABASE_TABLE + " VALUES (datetime()) ");
I am able to insert like date_created=2012-10-10 13:02:08 and I want this format 10 Oct 2012 12:48 how to achive this?
I prefer the following ways to get it done:
Create the table with a default settings to put current datetime automatically. For example:
ColumnName DATETIME DEFAULT CURRENT_TIMESTAMP
Create SimpleDateFormat and convert current date into SQL format
string. For example:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate = sdf.format(new Date());
ContentValues values = new ContentValues();
values.put("ColumnName", strDate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With