
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to filter a specific month in MySQL when date is in varchar?
- Want to fetch only the month part from a date in MySQL
- MySQL date comparison to fetch dates between a given range?
- MySQL query to update only month in date?
- MySQL query to fetch date with year and month?
- Fetch date record that equals today in MySQL
- MySQL to fetch records based on a specific month and year?
- Display only a specific duplicate record in MySQL
- How to select a specific record from MySQL if date is in VARCHAR format?
- How can fetch records from specific month and year in a MySQL table?
- Update record on a specific date matching the current date in MySQL
- How can we fetch month and day from a given date in MySQL?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- Filter dates from a table with DATE and NULL records in MySQL
- Use ObjectId under findOne() to fetch a specific record in MongoDB?

Advertisements