- 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
How to filter dates in MySQL to fetch date record only for a specific month?
Let us first create a table −
mysql> create table DemoTable ( AdmissionDate varchar(100) ); Query OK, 0 rows affected (1.06 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2018-01-21'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-08-13'); Query OK, 1 row affected (0.56 sec) mysql> insert into DemoTable values('2019-07-08'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2016-02-12'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 2018-01-21 | | 2019-08-13 | | 2019-07-08 | | 2016-02-12 | +---------------+ 4 rows in set (0.00 sec)
Following is the query to filter dates in MySQL and fetch date record only for August month −
mysql> select *from DemoTable where AdmissionDate like '2019-08%';
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 2019-08-13 | +---------------+ 1 row in set (0.04 sec)
Advertisements