- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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.
- Related Articles
- What is the difference between MySQL NOW() and CURDATE() function?
- What is the difference between SQL and MySQL?
- What is the difference between MySQL stored procedure and function?
- What is the difference between CHAR and NCHAR in MySQL?
- What is the difference between CHAR and VARCHAR in MySQL?
- What is the difference between MySQL TRUNCATE and DELETE command?
- What is the difference between UNIX TIMESTAMPS and MySQL TIMESTAMPS?
- In MySQL, what is the difference between SERIAL and AUTO_INCREMENT?
- What is the difference between MySQL LENGTH() and CHAR_LENGTH() function?
- What is the difference between MySQL LOCATE() and FIND_IN_SET() functions?
- What is the difference between MySQL INSTR() and FIND_IN_SET() functions?
- What is the difference between int and integer in MySQL?
- What is the difference between BIT and TINYINT in MySQL?
- Difference between “now” and a given date with MongoDB?
- What is the difference between MySQL ISNULL() function and IS NULL operator?
