mysql> SELECT DAYOFWEEK('0-2-1');
results in the following:
+--------------------+
| DAYOFWEEK('0-2-1') |
+--------------------+
| 3 |
+--------------------+
WEEKDAY(date) different and returns the weekday index for the given date(0=Monday, 1=Tuesday,
2=Wednesday, and so on).
mysql> SELECT DAYOFWEEK('0-2-1');
results in the following:
+--------------------+
| DAYOFWEEK('0-2-1') |
+--------------------+
| 3 |
+--------------------+
Getting Names for Months and Days
There are two functions that can be used to look up month and day names for a given date:
MONTHNAME(date)
DAYNAME(date)
MONTHNAME(date) can be used to obtain the name of the month in which date occurs as a string:
mysql> SELECT MONTHNAME('0-2-1');
results in the following:
+--------------------+
| MONTHNAME('0-2-1') |
+--------------------+
| February |
+--------------------+
DAYNAME(date) is similar:
mysql> SELECT DAYNAME('2000-01-01');
results in the following:
+-----------------------+
| DAYNAME('2000-01-01') |
+-----------------------+
| Saturday |
+-----------------------+
But remember, date must be a valid date, or the function will fail. Thus, an illegal date returns a NULL
result:
mysql> SELECT MONTHNAME('9');
produces the following:
+----------------+
| MONTHNAME('9') |
+----------------+