Lesson

MySQL NOW() Function

10 min reading
Free Course

MySQL NOW() Function

The MySQL NOW() function returns the current date and time in the session time zone. In string contexts, it formats as 'YYYY-MM-DD hh:mm:ss'. In numeric contexts, it returns YYYYMMDDhhmmss.

NOW() is the standard function for stamping created_at columns, auditing logins, and filtering records relative to the current moment. You can pass an optional fractional seconds precision argument from 0 to 6.

Crucially, NOW() returns the timestamp when the current SQL statement began executing. Every call to NOW() inside the same query returns the exact same value, even if the query runs for several seconds.

Syntax

NOW([fsp])
  • fsp: Optional integer from 0 to 6 specifying fractional seconds precision. Defaults to 0.

Practical Example

In demo_orders, you can find orders placed within the last 24 hours by comparing created_at against NOW() minus an interval.

SELECT
    order_id,
    customer_id,
    created_at,
    NOW() AS query_started_at
FROM demo_orders
WHERE created_at >= NOW() - INTERVAL 24 HOUR
ORDER BY created_at DESC;
order_id customer_id created_at query_started_at
1088 14 2026-05-10 13:45:10 2026-05-10 15:00:00
1085 27 2026-05-10 08:12:04 2026-05-10 15:00:00

Every row shows the same query_started_at timestamp because NOW() stays constant for the entire statement.

Common Mistakes & NULL Behavior

Developers often confuse NOW() with SYSDATE(). Calling SELECT NOW(), SLEEP(2), NOW() returns two identical timestamps because NOW() uses statement start time. By contrast, SYSDATE() returns the wall-clock time at each evaluation, so the second call is two seconds later.

NOW() takes no required input arguments, so it never fails because of a NULL argument. However, passing an invalid fsp outside 0 to 6 (such as NOW(7) or NOW(NULL)) raises a syntax or argument error.

Another common oversight involves time zones. NOW() reflects @@session.time_zone. If your app servers connect with different session time zones, NOW() produces inconsistent local timestamps unless you enforce 'UTC' per connection or use UTC_TIMESTAMP().

Frequently Asked Questions

What is the difference between NOW() and CURRENT_TIMESTAMP?

They are exact synonyms in MySQL. Both return the statement start timestamp, accept optional fsp (0 to 6), and work identically in queries and DEFAULT column definitions.

Why does NOW() return the same value after SLEEP(5)?

MySQL evaluates NOW() once at statement start to keep results consistent and replication-safe. Use SYSDATE() if you truly need live elapsed wall-clock time mid-query.

Can I use NOW(3) as a default column value?

Yes. In MySQL 5.6.5 and later, DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3) or DEFAULT NOW(3) is valid on table definitions.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum