jax
jax

Reputation: 38573

SQLite and inserting the current date in UTC format

How do I use an SQL statement on an sqllite database to insert the current date in UTC. I found the NOW function but what format is that in? This will be on mobile devices so everyone will have a different locale, however, I need a standard time format because the device will compare the dates with my server.

Also, is there a way to automatically update a 'modified' field when the data in the row is changed like you can in MySQL?

Upvotes: 14

Views: 28141

Answers (2)

liggett78
liggett78

Reputation: 11358

SELECT DATETIME('now') returns the current UTC datetime. See Date And Time Functions. You can use DATETIME DEFAULT CURRENT_TIMESTAMP with column declaration.

Format 11, the string 'now', is converted into the current date and time as obtained from the xCurrentTime method of the sqlite3_vfs object in use. Universal Coordinated Time (UTC) is used

For the 'modified' field you can use a trigger.

Upvotes: 19

teukkam
teukkam

Reputation: 4317

You don't specify what you use to develop your application on. I prefer using QDate::toJulianDay and QDate::fromJulianDay in Qt to store dates in an SQLite database as an integer if I only need to store the date.

Upvotes: 3

Related Questions