- 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
Select rows from a table with date between 90 days ago and now in MySQL
Use MySQL INTERVAL for this. Let us first create a table −
mysql> create table DemoTable ( DueDate date ); Query OK, 0 rows affected (1.13 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-07-10'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2019-09-02'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-06-01'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('2019-05-10'); Query OK, 1 row affected (0.13 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 −
+------------+ | DueDate | +------------+ | 2019-07-10 | | 2019-09-02 | | 2019-06-01 | | 2019-05-10 | | 2019-08-21 | +------------+ 5 rows in set (0.00 sec)
Following is the query to select rows from a table with a date between - 90days ago and now −
mysql> select *from DemoTable where DueDate between now() - interval 90 day and now();
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-07-10 | | 2019-08-21 | +------------+ 2 rows in set (0.00 sec)
- Related Articles
- Display dates after NOW() + 10 days from a MySQL table?
- Select rows from a MySQL table and display using IN()
- Add 30 days to date in a MySQL table with arrival date records
- MySQL select query to select rows from a table that are not in another table?
- SELECT MySQL rows where today's date is between two DATE columns?
- Randomly SELECT distinct rows in a MySQL table?
- Difference between “now” and a given date with MongoDB?
- Select dates between current date and 3 months from the current date in MySQL?
- Fetch random rows from a table with MySQL
- How to insert a row with a timestamp “X days ago” in MySQL?
- Find the difference between current date and the date records from a MySQL table
- Select records from MySQL NOW() -1 Day?
- Filter dates from a table with DATE and NULL records in MySQL
- How to select all rows from a table except the last one in MySQL?
- How to select rows in MySQL that are >= 1 DAY from the current date?

Advertisements