MySQL CURDATE Function
Summary: in this tutorial, you will learn how to use the MySQL CURDATE()
function to get the current date.
Introduction to MySQL CURDATE
function
The CURDATE()
the function returns the current date as a value in the 'YYYY-MM-DD'
format if it is used in a string context or YYYMMDD
format if it is used in a numeric context.
The following example shows how the CURDATE()
the function is used in the string context.
mysql> SELECT CURDATE();
+------------+
| CURDATE() |
+------------+
| 2017-07-13 |
+------------+
1 row in set (0.00 sec)
And the following example illustrates how the CURDATE()
the function is used in a numeric context:
mysql> SELECT CURDATE() + 0;
+---------------+
| CURDATE() + 0 |
+---------------+
| 20170713 |
+---------------+
1 row in set (0.04 sec)
The CURRENT_DATE
and CURRENT_DATE()
are synonyms for CURDATE()
.
mysql> SELECT CURRENT_DATE(),
CURRENT_DATE,
CURDATE();
+----------------+--------------+------------+
| CURRENT_DATE() | CURRENT_DATE | CURDATE() |
+----------------+--------------+------------+
| 2017-07-13 | 2017-07-13 | 2017-07-13 |
+----------------+--------------+------------+
1 row in set (0.00 sec)
CURDATE vs. NOW
The CURDATE()
the function returns the current date with the date part only while the NOW()
the function returns both date and time parts of the current time.
The result of the CURDATE()
the function is equivalent to the following expression:
mysql> SELECT DATE(NOW());
+-------------+
| DATE(NOW()) |
+-------------+
| 2017-07-13 |
+-------------+
1 row in set (0.00 sec)
In this tutorial, you have learned how to use the MySQL CURDATE()
function to get the current date value.
0 Comments
CAN FEEDBACK
Emoji