MySQL now () sysdate () curdate () difference

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.