How to Get the Current Date and Time in SQLite with datetime('now')
Notes, orders and log lines usually record when they were made. SQLite's datetime('now') returns the current date and time, and a column default can fill it in on every insert. This guide reads the clock and stamps a note with it, with real output from SQLite 3.54.1.
Syntax
SELECT datetime('now');
SELECT date('now');
SELECT time('now');
| Part | What it means |
|---|---|
datetime('now') | The current date and time, as YYYY-MM-DD HH:MM:SS |
date('now') | Only the date, as YYYY-MM-DD |
time('now') | Only the time, as HH:MM:SS |
All three use UTC, not your computer's time zone. SQLite's documentation on date and time functions: "Format 11, the string 'now', is converted into the current date and time". It goes on: "Universal Coordinated Time (UTC) is used."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as current_time.sql:
SELECT datetime('now'), date('now'), time('now');
CREATE TABLE notes (
body TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
INSERT INTO notes (body) VALUES ('Water the plants');
SELECT * FROM notes;

- The first
SELECTreads the clock three ways. created_at TEXT NOT NULL DEFAULT (datetime('now'))stamps each new note with the time it's inserted. A function call in a default has to be wrapped in parentheses.- The
INSERTgives only the note's text.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table notes.db ".read current_time.sql"
sqlite3 opens the database file notes.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+---------------------+-------------+-------------+
| datetime('now') | date('now') | time('now') |
+---------------------+-------------+-------------+
| 2026-12-03 09:36:27 | 2026-12-03 | 09:36:27 |
+---------------------+-------------+-------------+
+------------------+---------------------+
| body | created_at |
+------------------+---------------------+
| Water the plants | 2026-12-03 09:36:27 |
+------------------+---------------------+

The three functions returned the same moment in three forms, and the note got that time in created_at without its INSERT mentioning the column. Your run shows your own date and time, in UTC.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A default without parentheses, DEFAULT datetime('now') | Parse error ...: near "(": syntax error | Wrap the call: DEFAULT (datetime('now')) |
| Expecting your local time | The times are UTC, so they can be hours off your clock | Store UTC, and convert only to show it: datetime('now', 'localtime') |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The stored time is hours off | 'now' is UTC | Add 'localtime' when you display the time |
Parse error near line 3 of current_time.sql: table notes already exists | The script already ran on notes.db | Delete notes.db and run the script again |
FAQ
Is CURRENT_TIMESTAMP the same as datetime('now')?
It gives the same form. A column with DEFAULT CURRENT_TIMESTAMP stored 19 characters, equal to datetime('now'). CURRENT_TIMESTAMP is a keyword, so it needs no parentheses.
How do I convert to local time?
With the 'localtime' modifier: datetime('now', 'localtime'). The documentation: "The "localtime" modifier assumes the time-value to its left is in Universal Coordinated Time (UTC) and adjusts that time value so that it is in localtime."
Does 'now' change during one statement?
No. datetime('now') = datetime('now') gave 1. The documentation: "The 'now' argument to date and time functions always returns exactly the same value for multiple invocations within the same sqlite3_step() call."
Conclusion
datetime('now') read the current UTC time, and DEFAULT (datetime('now')) stamped it on the new note without the INSERT asking.
Additional Resources
- Date And Time Functions —
'now', the other time values and every modifier. - The DEFAULT clause — defaults, including
CURRENT_TIMESTAMP.
