Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 847
jax Avatar asked Nov 24 '10 11:11

jax


People also ask

How do I get the current date in SQLite?

The SQLite function DATE('now') returns the current date as a text value. It uses the 'YYYY-MM-DD' format, where YYYY is a 4-digit year, MM is a 2-digit month, and DD is a 2-digit day of the month. This function takes one argument: the text 'now' indicates the current date and time.

How do I change the date format in SQLite?

Use the STRFTIME() function to format date\time\datetime data in SQLite. This function takes two arguments. The first argument is a format string containing the date/time part pattern. In our example, we use the format string '%d/%m/%Y, %H:%M'.


1 Answers

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.

like image 174
liggett78 Avatar answered Sep 28 '22 09:09

liggett78