MySQL LOCALTIMESTAMP() Function
MySQL LOCALTIMESTAMP(): Capture the Session Timestamp
LOCALTIMESTAMP and LOCALTIMESTAMP() return the current date and time in the MySQL session's time zone. Like LOCALTIME(), it is a direct synonym for NOW() and CURRENT_TIMESTAMP(), supporting optional fractional seconds up to six digits.
Audit logs and employee activity trackers use LOCALTIMESTAMP() for explicit SQL-standard timestamping in queries and table defaults.
Syntax
Call LOCALTIMESTAMP with or without parentheses, or pass a precision literal 0 through 6:
LOCALTIMESTAMP
LOCALTIMESTAMP()
LOCALTIMESTAMP(fsp)
fsp: Optional integer literal from0to6for fractional seconds.
In string context, it produces 'YYYY-MM-DD HH:MM:SS[.ffffff]', and in numeric context (LOCALTIMESTAMP + 0), it produces YYYYMMDDHHMMSS[.ffffff].
Practical Example
Suppose your HR portal records badge audits for active staff in demo_employees, stamping each row with microsecond-level precision (fsp = 3).
SELECT
employee_id,
full_name,
last_seen_at,
LOCALTIMESTAMP(3) AS audit_recorded_at
FROM demo_employees
WHERE employee_id IN (11, 12);
| employee_id | full_name | last_seen_at | audit_recorded_at |
|---|---|---|---|
| 11 | Nadia Rahman | 2026-05-12 08:55:10 | 2026-05-12 10:22:19.804 |
| 12 | Tariq Hasan | NULL | 2026-05-12 10:22:19.804 |
Even though employee 12 has a NULL value in last_seen_at, LOCALTIMESTAMP(3) still outputs the full audit timestamp cleanly.
Common Mistakes & NULL Behavior
Keep these rules in mind when using LOCALTIMESTAMP():
- Takes no required inputs (immune to
NULLcolumns):NULLvalues in any table column cannot makeLOCALTIMESTAMP()fail or returnNULL. - Invalid
fspraises a syntax error: Only integer literals0to6are accepted. PassingLOCALTIMESTAMP(NULL)orLOCALTIMESTAMP(9)is invalid. - Constant per statement, not per row: Even in long-running
INSERTorUPDATEstatements,LOCALTIMESTAMP()returns the moment the statement started, not the wall clock for each row. - Do not confuse with UTC:
LOCALTIMESTAMP()uses@@session.time_zone. CallUTC_TIMESTAMP()when storing zone-independent UTC timestamps asDATETIME.
Frequently Asked Questions
Can I use LOCALTIMESTAMP as a column DEFAULT value?
Yes. In MySQL, LOCALTIMESTAMP and LOCALTIMESTAMP(fsp) are valid synonyms for CURRENT_TIMESTAMP in DEFAULT and ON UPDATE column definitions.
What is the difference between LOCALTIMESTAMP() and SYSDATE()?
LOCALTIMESTAMP() returns the statement start time and stays constant throughout the query, whereas SYSDATE() returns the live execution time at each evaluation.
Does LOCALTIMESTAMP() include the time zone offset like '+00:00'?
No. MySQL DATETIME values never embed a time zone offset suffix; they format strictly as 'YYYY-MM-DD HH:MM:SS[.ffffff]'.
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.