MySQL Now Function

The MySQL Now Function returns the current date and time based on the current system time on the server and the timezone that MySQL is configured to use.

This function is particularly useful when we need to fetch some data from our database, but the data we want must be of a certain age old with respect to the current time.

Note that the MySQL Now function returns the current date and time in this format: 'YYYY-MM-DD HH:MM:SS'.

Have a look at the rest of the tutorial below.

MySQL Now Syntax

The syntax for the MySQL Now function is as follows:


As you can see above, the function is pretty simple and takes no additional parameters. Let's go on to some examples.

MySQL Now Examples

Have a look at the following example of the NOW function at work:


The result will be a date/time in the following format:

2012-03-03 16:43:40

Note that you can also use the now function in your SQL as part of a where clause. Look at this:

SELECT * FROM books WHERE due_date < NOW();

The SQL above could be used as a simple check for all overdue library books.

Warnings about the MySQL Now Function

It is important to note that the NOW function returns the time when the SQL statement started to execute, so if you had the following query, the 2 NOW functions would return the exact same time!


If we wanted to get the exact time when the function itself was executed, we would need to use the SYSDATE function, as in this example:


Try them out for yourself and see. We hope you found this tutorial on the MySQL Now Function useful.

Link to this Page

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...