MySQL NOW() Function

MySQL NOW() function; In this tutorial, i am going to show you MySQL now() function with the help of examples.

MySQL NOW() Function

MySQL NOW() is used to returns the current date and time in query. It will return the value of two types format, first is the YYYY-MM-DD HH:MM:SS and second is the YYYYMMDDHHMMSS format. But it depends on the function is used to string or numeric context.

Syntax of MySQL NOW() Function

The basic syntax of mysql now() function; as follows:

NOW([fsp])

Note: fsp is optional. It means fractional second precision.

Example 1 – MySQL NOW() Function

Let’s take an example of mysql now() function; as follows:

SELECT NOW();

Output-1

 +---------------------+
 | NOW()               |
 +---------------------+
 | 2019-07-14 11:17:58 |
 +---------------------+

Example 2 – MySQL NOW() Function

Let’s take example using mysql now() with fsp argument or params; as follows:

SELECT NOW(3);

Output-2

 +----------------------------+
 | NOW(3)                     |
 +----------------------------+
 | 2019-07-14 05:12:06.095048 |
 +----------------------------+

Example 3- Get Current Date Data Using MySQL NOW()

To get or fetch current date data from mysql database table; you can use mysql now function; as follows:

 SELECT name, created_at
 FROM employees 
 WHERE DATE(created_at) = DATE(NOW()) ORDER BY id DESC

Example 4 – MySQL NOW() Function

Let’s take example using mysql now() with a numeric context; as follows:

SELECT NOW() + 2;

Output-4

 +----------------+
 | NOW() + 2      |
 +----------------+
 | 20190714055004 |
 +----------------+

Conclusion

MySQL NOW() Function tutorial , you have learned how to use MySQL NOW() function with various examples.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *