Difference between SYSDATE () And NOW () in MySQL

Source: Internet
Author: User


Difference between SYSDATE () And NOW () in MySQL five functions in MySQL need to calculate the value of the current time: NOW. return time. Format: 2012-09-23 06: 48: 28 CURDATE. Date of the returned time. Format: 2012-09-23CURTIME. Format: 06: 48: 28UNIX_TIMESTAMP, returns an integer timestamp of time, for example, 1348408108 SYSDATE. The return time is in the same format as the return time of the time () function, but there is a difference. In addition to the differences returned by definitions, the first four functions return the statement-based start execution time, while SYSDATE returns the value of time. Through comparison, we can find the differences between the two functions: www.2cto.com NOW () execute the following: [SQL] mysql> select now (), sleep (2), now (); + --------------------- + ---------- + --------------------- + | now () | sleep (2) | now () | + rows + ---------- + ------------------- + | 06:54:29 | 0 | 06:54:29 | + rows + ---------- + ----------------------- + 1 row in set (2.00 sec) The two returned values are the same, it indicates the start time of the statement. Run the following command on www.2cto.com SYSDATE: [SQL] mysql> select sysdate (), sleep (2), sysdate (); + ----------------------- + ---------- + ------------------- + | sysdate () | sleep) | sysdate () | + --------------------- + ---------- + ------------------- + | 06:55:00 | 0 | 06:55:02 | + ----------------------- + ---------- + rows + 1 row in set (2.01 sec) because of this difference, we usually use NOW () when executing the statement, because SYSDATE is obtained Real-time at that time, which may lead to different execution return values of the master database and slave database, resulting in inconsistent Master/Slave Data. Other functions on www.2cto.com are executed as follows: [SQL] mysql> select now (), sysdate (), curdate (), curtime (), unix_timestamp () \ G; * *************************** 1. row ************************** now (): 07:00:05 sysdate (): 07:00:05 curdate (): 2012-09-23 curtime (): 07:00:05 unix_timestamp (): 1348408805 1 row in set (0.00 sec)

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.