In MariaDB, CURRENT_DATE
and CURRENT_DATE()
are synonyms for CURDATE()
.
The CURDATE()
function is a built-in date and time function that returns the current date.
The date is returned in either 'YYYY-MM-DD'
or YYYYMMDD
, depending on whether the function is being used in a string or numeric context.
Syntax
The syntax goes like this:
CURRENT_DATE
CURRENT_DATE()
No arguments are required or accepted.
You can alternatively call CURDATE()
like this:
CURDATE()
Example
Here’s an example:
SELECT
CURRENT_DATE,
CURRENT_DATE(),
CURDATE();
Result:
+--------------+----------------+------------+ | CURRENT_DATE | CURRENT_DATE() | CURDATE() | +--------------+----------------+------------+ | 2021-05-08 | 2021-05-08 | 2021-05-08 | +--------------+----------------+------------+
We can see that all three return the same result.
Numeric Context
When used in a numeric context, the resulting date is in YYYYMMDD
format.
Example:
SELECT
CURRENT_DATE + 0,
CURRENT_DATE() + 0;
Result:
+------------------+--------------------+ | CURRENT_DATE + 0 | CURRENT_DATE() + 0 | +------------------+--------------------+ | 20210508 | 20210508 | +------------------+--------------------+
Adding to the Current Date
There are many ways to perform arithmetic on dates in MariaDB. You can use such methods to add a number of days, weeks, months, or years to the current date.
Here’s an example of using the addition operator (+
) to add 10 days to the date:
SELECT
CURRENT_DATE,
CURRENT_DATE() + INTERVAL 10 DAY;
Result:
+--------------+----------------------------------+ | CURRENT_DATE | CURRENT_DATE() + INTERVAL 10 DAY | +--------------+----------------------------------+ | 2021-05-08 | 2021-05-18 | +--------------+----------------------------------+
Also see functions like DATE_ADD()
and ADDDATE()
for an alternative way to add to the current date.
Subtracting from the Current Date
Here’s an example of using the subtraction operator (-
) to subtract 10 days from the current date:
SELECT
CURRENT_DATE(),
CURRENT_DATE() - INTERVAL 10 DAY;
Result:
+----------------+----------------------------------+ | CURRENT_DATE() | CURRENT_DATE() - INTERVAL 10 DAY | +----------------+----------------------------------+ | 2021-05-08 | 2021-04-28 | +----------------+----------------------------------+
See functions like DATE_SUB()
and SUBDATE()
for an alternative way to add to the current date.
No Arguments
No arguments are accepted. Here’s what happens when we pass an argument:
SELECT CURRENT_DATE(1);
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1)' at line 1