

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to subtract date records with week day and display the weekday with records
For this, you can use DATE_FORMAT(). Let us first create a table −
mysql> create table DemoTable1820 ( AdmissionDate varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1820 values('20/10/2019'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1820 values('19/12/2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1820 values('16/04/2017'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1820;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 20/10/2019 | | 19/12/2018 | | 16/04/2017 | +---------------+ 3 rows in set (0.00 sec)
Here is the query to subtract date records with week day and display week day name along with records −
mysql> select DATE_FORMAT(SUBDATE(STR_TO_DATE(AdmissionDate,'%d/%m/%y'), WEEKDAY(STR_TO_DATE(AdmissionDate,'%d/%m/%y'))), '%a %d %b') from DemoTable1820;
This will produce the following output −
+-------------------------------------------------------------------------------------------------------------------------+ | DATE_FORMAT(SUBDATE(STR_TO_DATE(AdmissionDate,'%d/%m/%y'), WEEKDAY(STR_TO_DATE(AdmissionDate,'%d/%m/%y'))), '%a %d %b') | +-------------------------------------------------------------------------------------------------------------------------+ | Mon 19 Oct | | Mon 14 Dec | | Mon 13 Apr | +-------------------------------------------------------------------------------------------------------------------------+ 3 rows in set, 6 warnings (0.00 sec)
- Related Questions & Answers
- MySQL query to select records with a particular date?
- MySQL query to select records with a particular date and time?
- How to display first day and last day of the month from date records in MySQL?
- Fetch date records comparing with the current date’s day and month in MySQL
- Get Nth weekday of the month from a column with DATE records in MySQL
- MySQL query to display the count of distinct records from a column with duplicate records
- MySQL query to fetch the latest date from a table with date records
- Display month names and year from a column with date records with MySQL
- MongoDB query to search date records using only Month and Day
- MySQL query to return all records with a datetime older than 1 week
- How to compare Year, Month and Day in a MySQL query and display matching records
- Display distinct dates in MySQL from a column with date records
- How to change the date in a table with date records with MySQL?
- How to display the day name on the basis of Date of Birth records in MySQL?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
Advertisements