- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get day name for the corresponding date in MySQL?
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)
Advertisements