now() — Start time of the current transaction
Last updated: 2026-11-04
now() — Start time of the current transaction
now() returns the start time of the current transaction as a timestamp with time zone. It stays fixed for the whole transaction, so every statement in it sees the same instant — which is exactly why it beats clock_timestamp() for audit timestamps: all rows written by one transaction carry an identical timestamp.
| Kind | function |
|---|---|
| Example Language | SQL |
📝 Syntax
now() → timestamp with time zone
Returns:timestamp with time zone — the start time of the current transaction, accurate to microseconds.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
days_ago | visits
----------+--------
0 | 1
1 | 1
2 | 2
(3 rows)
📌 Key Points
- now() is an alias for transaction_timestamp() and is constant within a transaction.
- Use clock_timestamp() when you need the real current time on every call; it returns the statement start time.
- Combined with date_trunc() it gives you day, week or month level grouping; the example expresses each bucket as a number of days ago so the output does not shift with the date you run it.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QHow is now() different from CURRENT_TIMESTAMP?
AThere is no difference — now() is the function form of CURRENT_TIMESTAMP, and both return the transaction start time.