MySQL - How to get the current date from your query

MySQL provides several date and time functions to help you get the current date from your query.

The functions that you can use to get the current date and time are as follows:

  • CURDATE() / CURRENT_DATE() / CURRENT_DATE
  • CURTIME() / CURRENT_TIME() / CURRENT_TIME
  • NOW() / CURRENT_TIMESTAMP()

All the functions and variables above return a string value by default.

The CURDATE() and CURRENT_DATE() functions return the current date value without the time value.

The default date format will be of YYYY-MM-DD as shown below:

SELECT CURDATE(), CURRENT_DATE(), CURRENT_DATE;
+------------+----------------+--------------+
| CURDATE()  | CURRENT_DATE() | CURRENT_DATE |
+------------+----------------+--------------+
| 2021-09-23 | 2021-09-23     | 2021-09-23   |
+------------+----------------+--------------+
1 row in set (0.00 sec)

Next, the CURTIME() and CURRENT_TIME() functions return the current time without the date as follows:

SELECT CURTIME(), CURRENT_TIME(), CURRENT_TIME;
+-----------+----------------+--------------+
| CURTIME() | CURRENT_TIME() | CURRENT_TIME |
+-----------+----------------+--------------+
| 16:38:39  | 16:38:39       | 16:38:39     |
+-----------+----------------+--------------+
1 row in set (0.00 sec)

Finally, the NOW() and CURRENT_TIMESTAMP() functions return both the current date and time values back as follows:

SELECT NOW(), CURRENT_TIMESTAMP();
+---------------------+---------------------+
| NOW()               | CURRENT_TIMESTAMP() |
+---------------------+---------------------+
| 2021-09-23 16:39:05 | 2021-09-23 16:39:05 |
+---------------------+---------------------+
1 row in set (0.00 sec)

If you do an addition or subtraction operation on the functions or variables above, then the returned value will be an integer value of yyyymmdd as shown below:

SELECT CURDATE() + 0;
+---------------+
| CURDATE() + 0 |
+---------------+
|      20210923 |
+---------------+
1 row in set (0.00 sec)

And that’s how you can get the MySQL current date and/or time value in using a SELECT statement and datetime functions.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.