MySQL Now function is one of the Date Function, which is used to return the current Date and Time in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuu format.
In this article, we will show you, How to use this Now function to get current date and time in MySQL with example.
MySQL NOW Syntax
The basic syntax of the NOW() Function in MySQL is as shown below:
MySQL NOW function Example
The following query will show you the basic use of this now function to get current date and time.
As you can see from the above screenshot, it returns today’s date and Time in YYYY-MM-DD HH:MM:SS format. Let us see another example with Alias Name.
SELECT NOW() AS 'Todays date and Time';
The following query will show you, what happens when add value to this now function.
SELECT NOW() + 5;
SELECT NOW(), NOW() + 5;
From the above screenshot, it added those values to current date and time. I mean, seconds to current date and time. Next, it is displaying the date in YYYYMMDDHHMMSS string format
MySQL NOW Example 2
In this example, we will show you, how to use this Now function on columns. Here, we are using datediff function to find the difference between now and the Hire Date column value.
For this demonstration, we are using Workbench to write a query against the customer database.
DATEDIFF(NOW(), HireDate) AS Difference
FROM `MySQL Tutorial`.customer;
Thank You for Visiting Our Blog