MySQL DAYNAME() Function
The MySQL DAYNAME() function returns the weekday name (Sunday, Monday, Tuesday, etc.) of a given date or datetime value.
Syntax
DAYNAME(datetime)
Parameters
datetime |
Required. Specify a date or datetime value from which to extract the weekday name. |
Return Value
Returns the weekday name of a given date or datetime value.
Example 1:
The example below shows the usage of DAYNAME() function.
mysql> SELECT DAYNAME('2018-08-18'); Result: 'Saturday' mysql> SELECT DAYNAME('2018-08-18 10:38:42'); Result: 'Saturday' mysql> SELECT DAYNAME('2018-08-18 10:38:42.000004'); Result: 'Saturday' mysql> SELECT DAYNAME('2014-10-20'); Result: 'Monday' mysql> SELECT DAYNAME(CURDATE()); Result: 'Wednesday'
Example 2:
Consider a database table called Orders with the following records:
OrderQuantity | Price | OrderTime |
---|---|---|
100 | 1.58 | 2017-08-18 10:38:42 |
120 | 1.61 | 2018-03-23 07:14:16 |
125 | 1.78 | 2018-09-12 05:25:56 |
50 | 1.80 | 2019-01-16 11:52:05 |
200 | 1.72 | 2020-02-06 09:31:34 |
The statement given below can be used to get the weekday name of records of column OrderTime:
SELECT *, DAYNAME(OrderTime) AS DAYNAME_Value FROM Orders;
This will produce the result as shown below:
OrderQuantity | Price | OrderTime | DAYNAME_Value |
---|---|---|---|
100 | 1.58 | 2017-08-18 10:38:42 | Friday |
120 | 1.61 | 2018-03-23 07:14:16 | Friday |
125 | 1.78 | 2018-09-12 05:25:56 | Wednesday |
50 | 1.80 | 2019-01-16 11:52:05 | Wednesday |
200 | 1.72 | 2020-02-06 09:31:34 | Thursday |
❮ MySQL Functions