Inserting current date and time in SQLite database Inserting current date and time in SQLite database sqlite sqlite

Inserting current date and time in SQLite database


SQLite supports the standard SQL variables CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP:

INSERT INTO Date (LastModifiedTime) VALUES(CURRENT_TIMESTAMP)

The default data type for dates/times in SQLite is TEXT.

ContentValues do not allow to use generic SQL expressions, only fixed values, so you have to read the current time in Java:

cv.put("LastModifiedTime",       new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));


INSERT INTO Date (LastModifiedTime) VALUES(DateTime('now'))

Use this site for further reference.


To get the current local(system) time, add the 'localtime' option:

select datetime('now', 'localtime');