MySQL LOCALTIME() Function
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 from0to6specifying 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 likeCURTIME(). In reality,LOCALTIME()returns a fullDATETIME(YYYY-MM-DD HH:MM:SS). UseCURRENT_TIME()if you only wantHH:MM:SS. - Never fails on
NULLrow data: BecauseLOCALTIME()takes no required column input,NULLfields in queried tables never turnLOCALTIME()intoNULL. fspmust be a literal0..6: PassingLOCALTIME(7), negative values, or a column triggers a syntax error.- Reflects
@@session.time_zone: "Local" means the MySQL connection'stime_zonesetting, 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.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.