MySQL SYSDATE() Function
MySQL SYSDATE() Function
The MySQL SYSDATE() function returns the current date and time at the exact moment the function executes. In string contexts, it outputs 'YYYY-MM-DD hh:mm:ss', while numeric contexts receive YYYYMMDDhhmmss.
Unlike NOW(), which locks to the start time of the SQL statement, SYSDATE() reads the system clock every time MySQL evaluates it. Inside long-running stored procedures, multi-row updates, or queries containing SLEEP(), SYSDATE() advances as wall-clock time passes.
You can pass an optional fractional seconds precision (fsp) between 0 and 6 to record millisecond or microsecond timing.
Syntax
SYSDATE([fsp])
fsp: Optional integer from0to6controlling fractional seconds precision. Defaults to0.
Practical Example
Suppose you run a benchmark or audit check on demo_orders where a slow step runs mid-query. Comparing NOW() and SYSDATE() demonstrates how SYSDATE() captures live elapsed time while NOW() stays fixed.
SELECT
order_id,
NOW(3) AS statement_start,
SYSDATE(3) AS before_pause,
SLEEP(1) AS pause_result,
SYSDATE(3) AS after_pause
FROM demo_orders
WHERE order_id = 901;
| order_id | statement_start | before_pause | pause_result | after_pause |
|---|---|---|---|---|
| 901 | 2026-05-10 16:00:00.100 | 2026-05-10 16:00:00.102 | 0 | 2026-05-10 16:00:01.104 |
Look at after_pause: SYSDATE(3) advances by one full second after SLEEP(1), while statement_start stays frozen.
Common Mistakes & NULL Behavior
Because SYSDATE() changes value mid-statement, it is non-deterministic for statement-based binary replication. Replicas executing the same INSERT or UPDATE later can record slightly different timestamps unless you start MySQL with --sysdate-is-now or use row-based replication.
Also note that SYSDATE() prevents MySQL from using index optimizations in certain WHERE comparisons, because the value is not treated as a statement-level constant. Prefer NOW() for standard WHERE created_at >= ... filters.
SYSDATE() takes no required arguments, so it never fails due to a NULL input argument. However, passing an invalid fsp outside 0 to 6 (including SYSDATE(NULL) or SYSDATE(7)) produces an error.
Frequently Asked Questions
When should I use SYSDATE() instead of NOW()?
Use SYSDATE() when benchmarking steps inside stored routines, logging exact step completion times, or measuring delays inside a single long query. Use NOW() for regular queries and row timestamps.
Why did SYSDATE() return the same value as NOW() on our server?
Your MySQL server may be configured with the --sysdate-is-now startup option, which aliases SYSDATE() to NOW() for replication safety.
Does SYSDATE() respect session time_zone?
Yes. Like NOW(), SYSDATE() formats its output according to the current @@session.time_zone setting.
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.