There are 5 functions in MySQL that need to calculate the value of the current time:
- Now. Return time, format as: 2012-09-23 06:48:28
- Curdate, returns the date of the time, formatted as: 2012-09-23
- Curtime, return time, format such as: 06:48:28
- Unix_timestamp, returns the time integer stamp, such as: 1348408108
- Sysdate, the return time, the format and time () function return times, but there are differences.
In addition to the differences that are returned by the definition itself, the other difference is that the first four functions return the start-of-execution time based on the statement, and Sysdate returns the value of the hour.
By comparison, you can find the difference between these two functions:
Now () do the following:
- Mysql> Select Now (), Sleep (2), now ();
- +---------------------+----------+---------------------+
- | Now () | Sleep (2) | Now () |
- +---------------------+----------+---------------------+
- | 2012-09-23 06:54:29 | 0 | 2012-09-23 06:54:29 |
- +---------------------+----------+---------------------+
- 1 row in Set (2.00 sec)
The two values it returns are the same because they represent the time at which the statement started executing.
Sysdate is executed as follows:
- mysql> Select Sysdate (), Sleep (2), sysdate ();
- +---------------------+----------+---------------------+
- | Sysdate () | Sleep (2) | Sysdate () |
- +---------------------+----------+---------------------+
- | 2012-09-23 06:55:00 | 0 | 2012-09-23 06:55:02 |
- +---------------------+----------+---------------------+
- 1 row in set (2.01 sec)
Because of this difference, we generally use now () when executing the statement, because Sysdate gets the time in real time, which could cause the main library and the return value from the library to be executed differently, leading to inconsistent master-slave data.
Other functions on it are performed as follows:
Differences and connections between the sysdate () and now () functions in MySQL