Home Functions NOW()
SQL Date & Time Function

NOW()

NOW() returns the current date and time as a single datetime value. CURRENT_TIMESTAMP is the ANSI portable spelling that works on every engine, while SQL Server uses GETDATE() or SYSDATETIME().

MySQLPostgreSQLSQL Server
Returns: A datetime/timestamp value holding the current date and time at statement or transaction start.

Syntax

NOW()CURRENT_TIMESTAMPGETDATE()SYSDATETIME()
ParameterTypeRequiredDescription
(none) n/a no NOW() takes no arguments in MySQL and PostgreSQL; it returns the current date and time.
precision integer no MySQL only: NOW(fsp) accepts 0 to 6 for fractional-seconds precision, for example NOW(3) for milliseconds.

How it works

NOW() gives you the current date and time in one value. In both MySQL and PostgreSQL you call it as NOW(), and it is the function you reach for when stamping a row with the moment it was created or updated. The ANSI SQL standard spelling for the same idea is CURRENT_TIMESTAMP, which is portable and works on every major engine, so it is the safest choice when you want one query to run everywhere.

SQL Server does not have NOW(). There you use GETDATE() for local server time, SYSDATETIME() when you need higher (100 nanosecond) precision, or GETUTCDATE() for UTC. CURRENT_TIMESTAMP is also accepted in SQL Server and maps to GETDATE(), which is why it is the most transferable form across MySQL, PostgreSQL and SQL Server.

An important detail in PostgreSQL: NOW() and CURRENT_TIMESTAMP return the time the current transaction started, not the instant the function runs, so they stay constant for the whole transaction. If you need the real wall clock at the moment of evaluation, use clock_timestamp(). See CURRENT_DATE for the date-only companion and DATEADD for shifting a timestamp by an interval.

Examples

Stamp a new row with the current time

-- CURRENT_TIMESTAMP is portable; NOW() works in MySQL and PostgreSQL
INSERT INTO orders (customer_id, created_at)
VALUES (42, NOW());
Result
created_at
-------------------
2026-07-05 14:03:27

Per-engine equivalents for current date and time

-- MySQL
SELECT NOW();
-- PostgreSQL
SELECT NOW();          -- or CURRENT_TIMESTAMP
-- SQL Server
SELECT GETDATE();      -- or SYSDATETIME(), CURRENT_TIMESTAMP
Result
now
-------------------
2026-07-05 14:03:27

Compute age in days from NOW()

SELECT id,
       DATEDIFF(NOW(), created_at) AS age_days
FROM orders
ORDER BY age_days DESC;
Result
id | age_days
---+---------
 7 |      31
 4 |      12
 9 |       0

Default value CURRENT_TIMESTAMP in CREATE TABLE

CREATE TABLE orders (
  id         INT PRIMARY KEY,
  total      DECIMAL(10,2),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- created_at fills in automatically on INSERT
INSERT INTO orders (id, total) VALUES (1, 99.00);
Result
id | total | created_at
---+-------+--------------------
 1 | 99.00 | 2026-07-05 14:03:27

UTC versus local server time

-- MySQL
SELECT NOW() AS local_time, UTC_TIMESTAMP() AS utc_time;
-- SQL Server
SELECT GETDATE() AS local_time, GETUTCDATE() AS utc_time;
Result
local_time          | utc_time
--------------------+--------------------
2026-07-05 14:03:27 | 2026-07-05 11:03:27

Wall clock versus transaction time in PostgreSQL

-- NOW() is fixed for the whole transaction;
-- clock_timestamp() advances as the statement runs
SELECT NOW()             AS tx_start,
       clock_timestamp() AS wall_clock;
Result
tx_start                | wall_clock
------------------------+------------------------
2026-07-05 14:03:27.100 | 2026-07-05 14:03:27.842

Common mistakes

Wrong
-- In PostgreSQL both rows get the SAME time,
-- because NOW() is the transaction start time
BEGIN;
INSERT INTO log (msg, at) VALUES ('a', NOW());
INSERT INTO log (msg, at) VALUES ('b', NOW());
COMMIT;
Right
-- Use clock_timestamp() when each statement needs
-- the real instant it executes
BEGIN;
INSERT INTO log (msg, at) VALUES ('a', clock_timestamp());
INSERT INTO log (msg, at) VALUES ('b', clock_timestamp());
COMMIT;

In PostgreSQL NOW() and CURRENT_TIMESTAMP are constant within a transaction (and within a single statement). If you expect each call to advance, use clock_timestamp() instead.

Wrong
-- Assuming NOW() is UTC and storing it as if it were
INSERT INTO events (name, happened_at)
VALUES ('signup', NOW());
Right
-- Be explicit about the zone you store
-- MySQL:
INSERT INTO events (name, happened_at) VALUES ('signup', UTC_TIMESTAMP());
-- SQL Server:
INSERT INTO events (name, happened_at) VALUES ('signup', GETUTCDATE());

Time zone confusion is the classic bug. NOW() and GETDATE() return the server local time, not UTC. Decide whether you store local or UTC and use UTC_TIMESTAMP() or GETUTCDATE() when you mean UTC. See SQL data types explained for how timestamp columns store this.

Wrong
-- GETDATE() does not exist in MySQL or PostgreSQL
SELECT GETDATE();
Right
-- Use NOW() there, or CURRENT_TIMESTAMP everywhere
SELECT NOW();
SELECT CURRENT_TIMESTAMP;

GETDATE() is SQL Server only. On MySQL and PostgreSQL it raises an unknown-function error. Reach for CURRENT_TIMESTAMP when you want one expression that runs on all three engines.

Performance

NOW() is effectively free to evaluate: the server reads the clock (or the cached transaction start time) once, so calling it in a SELECT list or an INSERT adds no measurable cost. In PostgreSQL NOW() and CURRENT_TIMESTAMP are especially cheap because the transaction timestamp is already captured when the transaction begins.

Be careful using NOW() inside a WHERE clause on a large table, as in WHERE created_at > NOW() - INTERVAL 7 DAY. Keep the function on the constant side of the comparison and the bare column on the other side so the optimiser can still use an index on created_at. Wrapping the column in a function instead would force a full scan.

For default timestamps, prefer a column default of CURRENT_TIMESTAMP over setting the value in application code. The database fills it atomically at insert time, avoids a round trip, and keeps every row consistent even under concurrent writes.

Interview questions

What is the difference between NOW() and CURRENT_TIMESTAMP?

They return the same value: the current date and time. NOW() is the MySQL and PostgreSQL function form, while CURRENT_TIMESTAMP is the ANSI SQL standard keyword that works on every major engine, including SQL Server, which makes it the portable choice.

How do you get the current date and time in SQL Server, which has no NOW()?

Use GETDATE() for local server time, SYSDATETIME() for higher precision (100 nanoseconds), or GETUTCDATE() for UTC. CURRENT_TIMESTAMP also works and maps to GETDATE().

SELECT GETDATE(), SYSDATETIME(), GETUTCDATE();

In PostgreSQL, does NOW() change during a transaction?

No. NOW() and CURRENT_TIMESTAMP return the transaction start time and stay constant for the whole transaction. Use clock_timestamp() when you need the actual wall clock at the moment of evaluation.

How do you make a column default to the insert time?

Give the column a default of CURRENT_TIMESTAMP in the CREATE TABLE statement. The database sets it automatically on every INSERT that omits the column.

CREATE TABLE orders (
  id         INT PRIMARY KEY,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Does NOW() return UTC or local time?

It returns the server local time in both MySQL and PostgreSQL, governed by the session time zone. For UTC use UTC_TIMESTAMP() in MySQL or GETUTCDATE() in SQL Server.

Master SQL, one function at a time

Browse the full SQL functions library, or learn the fundamentals with our free, structured courses.