- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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)
- Related Articles
- How to validate expiry date on a MySQL query?
- MySQL query to delete a DATE older than 30 days from another date?
- How to find the previous and next record using a single query in MySQL?
- MySQL query to get next closest day between two days?
- How to return the nth record from MySQL query?
- MySQL query to fetch date more recent than 14 days?
- MySQL query to count days in date range with start and end date
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- Display record with today and tomorrow’s date from a column with date record in MySQL
- MySQL query to select date from timestamp?
- Find date record after a particular date from a column with VARCHAR type in MySQL
- MySQL Query to convert from datetime to date?
- MySQL select * and find record with current date
- Get the new record key ID from MySQL insert query?
- MySQL query to select date from 00:00 to today’s date

Advertisements