EN
MySQL - select between two dates
0 points
In this article, we would like to show you how to select between two dates in MySQL.
Quick solution:
xxxxxxxxxx
1
SELECT * FROM `table_name`
2
WHERE `column_name`
3
BETWEEN 'yyyy-mm-dd' AND 'yyyy-mm-dd';
To show how to select between two dates, we will use the following table:

Note:
At the end of this article you can find database preparation SQL queries.
In this example, we will select all the dates from events
table between 2000-01-05
and 2000-01-08
.
Query:
xxxxxxxxxx
1
SELECT * FROM `events`
2
WHERE (`event_date` BETWEEN '2021-01-05' AND '2021-01-08');
Output:

create_tables.sql
file:
xxxxxxxxxx
1
CREATE TABLE `events`(
2
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
3
`event_date` DATE,
4
PRIMARY KEY (`id`)
5
);
insert_data.sql
file:
xxxxxxxxxx
1
INSERT INTO `events`
2
(`event_date`)
3
VALUES
4
('2021-01-01'),
5
('2021-01-02'),
6
('2021-01-03'),
7
('2021-01-04'),
8
('2021-01-05'),
9
('2021-01-06'),
10
('2021-01-07'),
11
('2021-01-08'),
12
('2021-01-09'),
13
('2021-01-10');