Select the date records between two dates in MySQL


To select the date records between two dates, you need to use the BETWEEN keyword. Let us first create a table −

mysql> create table DemoTable681(AdmissionDate datetime);
Query OK, 0 rows affected (0.75 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable681 values('2019-01-21');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable681 values('2019-11-01');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable681 values('2019-12-03');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable681 values('2019-07-03');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable681 values('2019-02-04');
Query OK, 1 row affected (0.34 sec)
Display all records from the table using select statement:
mysql> select *from DemoTable681;

This will produce the following output −

+---------------------+
| AdmissionDate       |
+---------------------+
| 2019-01-21 00:00:00 |
| 2019-11-01 00:00:00 |
| 2019-12-03 00:00:00 |
| 2019-07-03 00:00:00 |
| 2019-02-04 00:00:00 |
+---------------------+
5 rows in set (0.00 sec)

Following is the query to select the date records between two dates −

mysql> select *from DemoTable681 where AdmissionDate between '2019-02-01' and '2019-12-01';

This will produce the following output −

+---------------------+
| AdmissionDate       |
+---------------------+
| 2019-11-01 00:00:00 |
| 2019-07-03 00:00:00 |
| 2019-02-04 00:00:00 |
+---------------------+
3 rows in set (0.00 sec)

Updated on: 26-Aug-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements