Difference between SYSDATE and NOW in MySQL

The sysdate() datetime function is similar to now(), except that now() gets the value at the beginning of execution, and sysdate() gets the value dynamically when the function executes.

 

mysql> select now(), sleep(3), now();

 

+---------------------+----------+---------------------+ 

| now() | sleep(3) | now() | 

+---------------------+----------+---------------------+ 

| 2015-04-12 16:00:00 | 0 | 2015-04-12 16:00:00 | 

+---------------------+----------+---------------------+

 

mysql> select sysdate(), sleep(3), sysdate();

+---------------------+----------+---------------------+ 

| sysdate() | sleep(3) | sysdate() | 

+---------------------+----------+---------------------+ 

| 2015-04-12 16:01:16 | 0 | 2015-04-12 16:01:19 | 

+---------------------+----------+---------------------+ 

It can be seen that although the sleep is 3 seconds in the middle, the time value of the now() function is the same twice; the time value obtained by the sysdate() function is different by 3 seconds.

 

sysdate() datetime function, rarely used in general.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326680527&siteId=291194637