sqlite database default time value 'now'
Is it possible in a sqlite database to craete a table that has a timestamp column that default to DATETIME('now')
?
Like this:
CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
t TIMESTAMP DEFAULT DATETIME('now')
);
This gives an error... How to resolve?
Solution 1:
i believe you can use
CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
t TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
);
as of version 3.1 (source)
Solution 2:
according to dr. hipp in a recent list post:
CREATE TABLE whatever(
....
timestamp DATE DEFAULT (datetime('now','localtime')),
...
);