
- 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
MySQL query to select all data between range of two dates?
To select all data between range of two dates, use MySQL BETWEEN −
select * from yourTableName where yourColumnName between yourDateValue1 and yourDateValue2;
Let us first create a −
mysql> create table DemoTable1422 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeJoiningDate date -> ); Query OK, 0 rows affected (0.69 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('John','2017-09-28'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Chris','2019-09-29'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Bob','2018-01-31'); Query OK, 1 row affected (0.55 sec) mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Sam','2018-12-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Mike','2019-11-10'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select −
mysql> select * from DemoTable1422;
This will produce the following output −
+------------+--------------+---------------------+ | EmployeeId | EmployeeName | EmployeeJoiningDate | +------------+--------------+---------------------+ | 1 | John | 2017-09-28 | | 2 | Chris | 2019-09-29 | | 3 | Bob | 2018-01-31 | | 4 | Sam | 2018-12-21 | | 5 | Mike | 2019-11-10 | +------------+--------------+---------------------+ 5 rows in set (0.00 sec)
Following is the query to select all data between range of two dates −
mysql> select * from DemoTable1422 where EmployeeJoiningDate between '2018-09-29' and '2019-09-29';
This will produce the following output −
+------------+--------------+---------------------+ | EmployeeId | EmployeeName | EmployeeJoiningDate | +------------+--------------+---------------------+ | 2 | Chris | 2019-09-29 | | 4 | Sam | 2018-12-21 | +------------+--------------+---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to query between two dates in MySQL?
- MySQL select dates in 30-day range?
- Select the date records between two dates in MySQL
- MySQL query to get the dates between range of records displaying student’s Date of Birth?
- How to list all dates between two dates in Excel?
- MySQL date comparison to fetch dates between a given range?
- How to select between/before/after dates in MySQL conditionally?
- Perform MySQL search between two dates
- MySQL query to calculate the days between two dates from different columns but similar rows
- MySQL select query to fetch data with null value?
- Return all dates between two dates in an array in PHP
- MySQL query to select all entries from a particular month
- MySQL Select IN range?
- MySQL query to select a record with two exact values?
- MySQL query to select a count on two separate conditions?

Advertisements