MariaDB WEEKDAY() Function

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

MariaDB WEEKDAY() Syntax

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

WEEKDAY(date)

Parameters

date

Required. A date or datetime expression.

If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'WEEKDAY'.

Return value

The MySQL WEEKDAY() function returns the weekday number of a given date, ranging from 0 to 6, and they respectively represent the following meanings:

  • 0-Monday
  • 1-Tuesday
  • 2-Wednesday
  • 3-Thursday
  • 4-Friday
  • 5-Saturday
  • 6-Sunday

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

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

MariaDB WEEKDAY() Examples

Here are some common examples of the Mariadb WEEKDAY() function.

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

Output:

WEEKDAY('2023-02-21'): 1
WEEKDAY('2023-02-22'): 2
WEEKDAY('2023-02-23'): 3
WEEKDAY('2023-02-24'): 4
WEEKDAY('2023-02-25'): 5
WEEKDAY('2023-02-26'): 6
WEEKDAY('2023-02-27'): 0

To return today’s weekday name, use NOW(), CURDATE(), CURRENT_DATE(), or SYSDATE(), for example:

SELECT
    WEEKDAY(NOW()),
    WEEKDAY(CURDATE()),
    WEEKDAY(CURRENT_DATE()),
    WEEKDAY(SYSDATE())\G

Output:

         WEEKDAY(NOW()): 3
     WEEKDAY(CURDATE()): 3
WEEKDAY(CURRENT_DATE()): 3
     WEEKDAY(SYSDATE()): 3

Note that your results may vary.

If you want to get the weekday name for a date, use the DAYNAME() function.

Conclusion

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