- 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
MySQL query to find expiry date (record) from the next 2 days?
For this, you can use BETWEEN keyword. Let us first create a table −
mysql> create table DemoTable ( ExpiryDate date ); Query OK, 0 rows affected (0.55 sec)
Note − Let’s say the current date is 2019-08-18.
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2018-01-21'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-08-20'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values('2018-08-20'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('2019-08-21'); 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 −
+------------+ | ExpiryDate | +------------+ | 2018-01-21 | | 2019-08-20 | | 2018-08-20 | | 2019-08-21 | +------------+ 4 rows in set (0.00 sec)
Here is the query to find expiry date within 2 days −
mysql> select *from DemoTable where ExpiryDate between curdate() AND curdate() + 2;
This will produce the following output −
+------------+ | ExpiryDate | +------------+ | 2019-08-20 | +------------+ 1 row in set (0.00 sec)
Advertisements