Get day name for the corresponding date in MySQL?

MySQLMySQLi Database

To fetch day name, use DAYNAME() function in MySQL. Let us first create a table −

mysql> create table DemoTable1954
   (
   ShippingDate date
   );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1954 values('2019-12-15');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1954 values('2018-04-11');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1954 values('2019-01-31');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1954 values('2016-10-01');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1954;

This will produce the following output −

+--------------+
| ShippingDate |
+--------------+
| 2019-12-15   |
| 2018-04-11   |
| 2019-01-31   |
| 2016-10-01   |
+--------------+
4 rows in set (0.00 sec)

Here is the query to get day name for the corresponding date:

mysql> select dayname(ShippingDate) as Day from DemoTable1954;

This will produce the following output −

+-----------+
| Day       |
+-----------+
| Sunday    |
| Wednesday |
| Thursday  |
| Saturday  |
+-----------+
4 rows in set (0.00 sec)
raja
Published on 31-Dec-2019 06:58:16
Advertisements