jagmohan
jagmohan

Reputation: 2052

Sqlite update DATETIME field not working

I am trying to update a DATETIME column in a Sqlite table using the following query.

String query = "UPDATE myTable SET displayed = datetime('now') where _id = " + id;
database.rawQuery(query, null);

I have tested this on both device and emulator but its not working, its not updating the value in the column.

PS: I tried the same query in Sqlite browser and its working there.

Please help me figure out a solution.

Thanks.

Upvotes: 1

Views: 6879

Answers (1)

Andrew T.
Andrew T.

Reputation: 4707

Instead of using rawQuery(), use execSQL() if the execution doesn't return any data.

String query = "UPDATE myTable SET displayed = datetime('now') where _id = " + id;
database.execSQL(query);

Though just a tip, it is better to use UNIX time if you really want to store and process date in the future. It will be more flexible and standardized.

Upvotes: 3

Related Questions