Sqlite - standard timestamp "now + few days"

I am trying to have a column that contains a timestamp value which is the default today + a few days

. Can this be done during table creation?

+3


source to share


1 answer


Yes, it can be done as in the following example:

sqlite> create table foo (i int, j text default (datetime('now', '+5 days')));
sqlite> insert into foo (i) values (1);
sqlite> select * from foo;
1|2012-04-11 07:49:04
sqlite> insert into foo (i) values (2);
sqlite> select * from foo;
1|2012-04-11 07:49:04
2|2012-04-11 07:49:14

      



If you only want to keep part of the date, use date

instead datetime

. Here I am using datetime

to show that the default expression is evaluated when inserted into the table, not when the table is created.

+2


source







All Articles