Now,curdate,curtime,sysdate differences in MySQL
1.now returns the time, in the following format: 2013-01-17 10:57:13
Mysql> Select Now (), Sleep (5), now ();
+---------------------+----------+---------------------+
| Now () | Sleep (5) | Now () |
+---------------------+----------+---------------------+
| 2013-01-17 10:57:13 | 0 | 2013-01-17 10:57:13 |
+---------------------+----------+---------------------+
1 row in Set (5.01 sec)
The two values it returns are the same because they represent the time at which the statement started executing.
2. Curdate, return the date of the time, in the following format: 2013-01-17
Mysql> Select Curdate (), Sleep (5), curdate ();
+------------+----------+------------+
| Curdate () | Sleep (5) | Curdate () |
+------------+----------+------------+
| 2013-01-17 | 0 | 2013-01-17 |
+------------+----------+------------+
1 row in Set (5.00 sec)
3.curtime, the return time, the format is as follows: 12:49:26
Mysql> Select Curtime (), Sleep (5), Curtime ();
+-----------+----------+-----------+
| Curtime () | Sleep (5) | Curtime () |
+-----------+----------+-----------+
| 12:49:26 | 0 | 12:49:26 |
+-----------+----------+-----------+
The two values it returns are the same because they represent the time at which the statement started executing.
4.sysdate returns the time, the format and time () function returns the same, but there is a difference. Format: 2013-01-17 13:02:40
Mysql> Select Sysdate (), Sleep (5), sysdate ();
+---------------------+----------+---------------------+
| Sysdate () | Sleep (5) | Sysdate () |
+---------------------+----------+---------------------+
| 2013-01-17 13:02:40 | 0 | 2013-01-17 13:02:45 |
+---------------------+----------+---------------------+
The two values it returns are not the same, because Sysdate is the system time to view the system time, always.
Because of this difference, we generally use now () when executing the statement, because Sysdate () obtains the
Real time, which may cause the main library to be different from the return value when executing from the library, causing the master-slave database to be inconsistent.
Difference: In addition to the differences returned by the definition itself, another difference is: Now (), Curtime (), Curdate ()
Is the return of the start execution time based on the statement, and Sysdate () returns the value of the hour.
Other function formats display:
Mysql> Select Now (), Curdate (), Sysdate (), Curtime () \g;
1. Row ***************************
Now (): 2013-01-17 13:07:53
Curdate (): 2013-01-17
Sysdate (): 2013-01-17 13:07:53
Curtime (): 13:07:53
1 row in Set (0.01 sec)
MySQL now () sysdate () curdate () difference