Lesson

MySQL LOCALTIME() Function

10 min reading
Free Course

MySQL LOCALTIME(): Return the Current Date and Time

LOCALTIME and LOCALTIME() return the current date and time as a DATETIME value in your session's time zone. Despite having "TIME" in its name, LOCALTIME() is an exact synonym for NOW() and includes both the date and the clock time.

Logging routines and scheduled jobs use LOCALTIME() when teams prefer standard SQL-style naming alongside fractional second precision.

Syntax

MySQL accepts three forms, with optional fractional seconds precision (fsp):

LOCALTIME
LOCALTIME()
LOCALTIME(fsp)
  • fsp: Optional integer literal from 0 to 6 specifying microsecond digits.

In string context, it returns 'YYYY-MM-DD HH:MM:SS[.ffffff]'. In numeric context (LOCALTIME + 0), it outputs YYYYMMDDHHMMSS[.ffffff].

Practical Example

Suppose your fulfillment dashboard queries demo_orders to label overdue pending orders with the exact local check timestamp.

SELECT
    order_id,
    status,
    due_at,
    LOCALTIME(2) AS checked_at
FROM demo_orders
WHERE status = 'pending'
  AND due_at < LOCALTIME();
order_id status due_at checked_at
610 pending 2026-05-12 09:00:00 2026-05-12 10:18:45.64
612 pending 2026-05-12 09:30:00 2026-05-12 10:18:45.64

Every matched row receives the exact same checked_at timestamp because LOCALTIME() evaluates once when the statement starts.

Common Mistakes & NULL Behavior

Watch for these pitfalls with LOCALTIME():

  • Includes the date, not just the time: Many developers assume LOCALTIME() behaves like CURTIME(). In reality, LOCALTIME() returns a full DATETIME (YYYY-MM-DD HH:MM:SS). Use CURRENT_TIME() if you only want HH:MM:SS.
  • Never fails on NULL row data: Because LOCALTIME() takes no required column input, NULL fields in queried tables never turn LOCALTIME() into NULL.
  • fsp must be a literal 0..6: Passing LOCALTIME(7), negative values, or a column triggers a syntax error.
  • Reflects @@session.time_zone: "Local" means the MySQL connection's time_zone setting, not the browser or application server OS clock if those differ.

Frequently Asked Questions

Is LOCALTIME() identical to NOW()?

Yes. LOCALTIME, LOCALTIME(), LOCALTIMESTAMP, CURRENT_TIMESTAMP, and NOW() are all synonyms in MySQL.

Can I use LOCALTIME without parentheses?

Yes. SELECT LOCALTIME; and SELECT LOCALTIME(); return the exact same value.

How does LOCALTIME() behave inside a stored procedure or transaction?

It returns the start time of each individual SQL statement inside the procedure, not the start time of the enclosing transaction.

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