MariaDB DAYNAME() Function

In MariaDB, DAYNAME() is a built-in function that returns the weekday name for a given date.

MariaDB DAYNAME() Syntax

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

DAYNAME(expr)

Parameters

expr

Required. A date or datetime expression.

Return value

The MariaDB DAYNAME() function returns the weekday name for a given date, and the return value will be one of the following values: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.

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

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

MariaDB DAYNAME() Examples

Basic usage

This statement shows the basic usage of the MariaDB DAYNAME() function:

SELECT
    DAYNAME('2022-02-21'),
    DAYNAME('2022-02-22'),
    DAYNAME('2022-02-23'),
    DAYNAME('2022-02-24'),
    DAYNAME('2022-02-25'),
    DAYNAME('2022-02-26'),
    DAYNAME('2022-02-27')\G

Output:

DAYNAME('2022-02-21'): Monday
DAYNAME('2022-02-22'): Tuesday
DAYNAME('2022-02-23'): Wednesday
DAYNAME('2022-02-24'): Thursday
DAYNAME('2022-02-25'): Friday
DAYNAME('2022-02-26'): Saturday
DAYNAME('2022-02-27'): Sunday

Invalid date

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

SELECT
    DAYNAME('2022-02-00'),
    DAYNAME('2022-02-30'),
    DAYNAME('Not A DATE')\G

Output:

DAYNAME('2022-02-00'): NULL
DAYNAME('2022-02-30'): NULL
DAYNAME('Not A DATE'): NULL

Current date

If you want to get the weekday name for the current date, use the CURDATE() or NOW() function:

SELECT DAYNAME(CURDATE()), DAYNAME(NOW());

Output:

+--------------------+----------------+
| DAYNAME(CURDATE()) | DAYNAME(NOW()) |
+--------------------+----------------+
| Saturday           | Saturday       |
+--------------------+----------------+

Other delimiters

The MariaDB DAYNAME() function allow you to construct dates with various separators:

SELECT
    DAYNAME('2023/01/08'),
    DAYNAME('2023,01!08'),
    DAYNAME('2023#01%08');

Output:

+-----------------------+-----------------------+-----------------------+
| DAYNAME('2023/01/08') | DAYNAME('2023,01!08') | DAYNAME('2023#01%08') |
+-----------------------+-----------------------+-----------------------+
| Sunday                | Sunday                | Sunday                |
+-----------------------+-----------------------+-----------------------+

Conclusion

In MariaDB, DAYNAME() is a built-in function that returns the weekday name for a given date.