MySQL WEEKDAY Function
The WEEKDAY
the function returns a weekday index for a date i.e., 0 for Monday, 1 for Tuesday, … 6 for Sunday.
The following illustrates the WEEKDAY
function:
WEEKDAY(date)
The WEEKDAY
the function accepts 1 argument which is a DATE
or nullDATETIME
value. It returns an integer that ranges from 0 to 6 that represents Monday to Sunday.
The WEEKDAY
function returns NULL
if the date is NULL
, invalid or zero ( 0000-00-00
).
See the following example:
mysql> SELECT DAYNAME('2010-01-01'), WEEKDAY('2010-01-01');
+-----------------------+-----------------------+
| DAYNAME('2010-01-01') | WEEKDAY('2010-01-01') |
+-----------------------+-----------------------+
| Friday | 4 |
+-----------------------+-----------------------+
1 row in set (0.00 sec)
In this example, we used the DAYNAME
function to get the weekday’s name and WEEKDAY
function to get the weekday index of January 1st, 2010
.
0 Comments
CAN FEEDBACK
Emoji