sqlite database default time value 'now'

Joep picture Joep · Oct 14, 2008 · Viewed 203.5k times · Source

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?

Answer

Owen picture Owen · Oct 14, 2008

i believe you can use

CREATE TABLE test (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  t TIMESTAMP
  DEFAULT CURRENT_TIMESTAMP
);

as of version 3.1 (source)