- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between MySQL NOW() and SYSDATE()?
MySQL NOW() and SYSDATE() functions returns the current timestamp values. But the output of both of them depends upon the execution time. This creates the big difference between them.
NOW() function returns a steady time that indicates the time at which the particular statement began to execute. In contrast, SYSDATE() function returns the accurate time at which the statement executes. Following example will show the difference between these functions −
mysql> Select NOW(), SLEEP(5), NOW(); +---------------------+----------+---------------------+ | NOW() | SLEEP(5) | NOW() | +---------------------+----------+---------------------+ | 2017-10-31 09:57:36 | 0 | 2017-10-31 09:57:36 | +---------------------+----------+---------------------+ 1 row in set (5.11 sec)
The above query shows that NOW() function returns the time at which it began to execute because even after 5 seconds of system sleep it returns the same value.
mysql> Select SYSDATE(), SLEEP(5), SYSDATE(); +---------------------+----------+---------------------+ | SYSDATE() | SLEEP(5) | SYSDATE() | +---------------------+----------+---------------------+ | 2017-10-31 09:58:13 | 0 | 2017-10-31 09:58:18 | +---------------------+----------+---------------------+ 1 row in set (5.00 sec)
In comparison, the above query shows that SYSDATE() function returns the time at which it executes because after 5 seconds of system sleep it returns the value which is actually increased by 5 seconds.
To Continue Learning Please Login
Login with Google