What is the difference between MySQL NOW() and SYSDATE()?


MySQL NOW() and SYSDATE() functions returns the current timestamp values. But the output of both of them depends upon the execution time. This creates the big difference between them.

NOW() function returns a steady time that indicates the time at which the particular statement began to execute. In contrast, SYSDATE() function returns the accurate time at which the statement executes. Following example will show the difference between these functions −

mysql> Select NOW(), SLEEP(5), NOW();
+---------------------+----------+---------------------+
| NOW()               | SLEEP(5) | NOW()               |
+---------------------+----------+---------------------+
| 2017-10-31 09:57:36 | 0        | 2017-10-31 09:57:36 |
+---------------------+----------+---------------------+
1 row in set (5.11 sec)

The above query shows that NOW() function returns the time at which it began to execute because even after 5 seconds of system sleep it returns the same value.

mysql> Select SYSDATE(), SLEEP(5), SYSDATE();

+---------------------+----------+---------------------+
| SYSDATE()           | SLEEP(5) | SYSDATE()           |
+---------------------+----------+---------------------+
| 2017-10-31 09:58:13 | 0        | 2017-10-31 09:58:18 |
+---------------------+----------+---------------------+
1 row in set (5.00 sec)

In comparison, the above query shows that SYSDATE() function returns the time at which it executes because after 5 seconds of system sleep it returns the value which is actually increased by 5 seconds.

Updated on: 30-Jan-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements