MySQL DAYOFWEEK Function
The DAYOFWEEK
the function returns the weekday index for a date i.e., 1 for Sunday, 2 for Monday, … 7 for Saturday. These index values correspond to the ODBC standard.
The following illustrates the DAYOFWEEK
function:
DAYOFWEEK(date)
The DAYOFWEEK
the function accepts 1 argument which is a DATE
or DATETIME
value. It returns an integer that ranges from 1 to 7 that represents Sunday to Saturday.
The DAYOFWEEK
function returns NULL
if the date is NULL
, zero ( 0000-00-00
), or invalid.
The following example returns the weekday index of December 1st, 2010
mysql> SELECT DAYNAME('2012-12-01'), DAYOFWEEK('2012-12-01');
+-----------------------+-------------------------+
| DAYNAME('2012-12-01') | DAYOFWEEK('2012-12-01') |
+-----------------------+-------------------------+
| Saturday | 7 |
+-----------------------+-------------------------+
1 row in set (0.00 sec)
In this query, the DAYNAME
the function returns weekday’s name while DAYOFWEEK
the function returns the weekday index of December 1st, 2011
.
0 Comments
CAN FEEDBACK
Emoji