sqliteHow do I store a timestamp in an SQLite database?
Storing a timestamp in an SQLite database is done by using the DATETIME
data type. This type is used to store date and time values in the format YYYY-MM-DD HH:MM:SS
. An example of how to store a timestamp in an SQLite database is shown below:
CREATE TABLE IF NOT EXISTS my_table (
id INTEGER PRIMARY KEY,
timestamp DATETIME NOT NULL
);
INSERT INTO my_table (timestamp) VALUES (datetime('now'));
The code above will create a table named my_table
with an id
integer primary key and a timestamp
column of type DATETIME
. The INSERT
statement will add a row to the table with the current timestamp.
Parts of the code:
CREATE TABLE
: This statement creates a new table in the database.IF NOT EXISTS
: This clause ensures that the table is only created if it does not already exist.DATETIME
: This is the data type used to store the timestamp.INSERT INTO
: This statement adds a row to the database table.datetime('now')
: This is a function that returns the current timestamp.
Helpful links
More of Sqlite
- How can SQLite and ZFS be used together for software development?
- How do I use SQLite with Visual Studio?
- How do I use the SQLite SUBSTRING function?
- How do I use an online SQLite viewer?
- How do I use the SQLite YEAR function?
- How can I use Python to update a SQLite database?
- How do I show the databases in SQLite?
- How can I use SQLite with Python to create a database?
- How do I use SQLite UNION to combine multiple SELECT queries?
See more codes...