MariaDB DATE() Function

In MariaDB, DATE() is a built-in function that extracts date parts from the gaven datetime expression.

MariaDB DATE() Syntax

This is the syntax of the MariaDB DATE() function:

DATE(expr)

Parameters

expr

Required. A date or datetime expression.

If you provide no parameters or the wrong number of parameters, MariaDB will report an error: 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 ')' at line 1.

Return value

The MariaDB DATE() function returns the date part from the specified date or datetime expression.

If the specified expression is not a valid date or datetime, the DATE() function will return NULL.

If the argument is NULL, the DATE() function will return NULL.

MariaDB DATE() Examples

Example 1

SELECT DATE('2023-01-08');

Output:

+--------------------+
| DATE('2023-01-08') |
+--------------------+
| 2023-01-08         |
+--------------------+

Example 2

MariaDB DATE() supports data and time expressions:

SELECT DATE('2023-01-08 10:11:12');

Output:

+-----------------------------+
| DATE('2023-01-08 10:11:12') |
+-----------------------------+
| 2023-01-08                  |
+-----------------------------+

Example 3

To get the current date:

SELECT
    NOW(),
    DATE(NOW());

Output:

+---------------------+-------------+
| NOW()               | DATE(NOW()) |
+---------------------+-------------+
| 2023-01-08 10:09:19 | 2023-01-08  |
+---------------------+-------------+

In this example, the NOW() function is used to return the current date and time.

Conclusion

In MariaDB, DATE() is a built-in function that extracts date parts from datetime expressions.