- 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 fetch date records greater than the current date after adding days with INTERVAL?
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AddDay int, PostDate date ); Query OK, 0 rows affected (2.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(AddDay,PostDate) values(20,'2019-08-04'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(AddDay,PostDate) values(7,'2019-08-20'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(AddDay,PostDate) values(45,'2019-07-01'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+------------+ | Id | AddDay | PostDate | +----+--------+------------+ | 1 | 20 | 2019-08-04 | | 2 | 7 | 2019-08-20 | | 3 | 45 | 2019-07-01 | +----+--------+------------+ 3 rows in set (0.00 sec)
Here is the query to fetch data records greater than current date after adding days from AddDay column −
mysql> select *from DemoTable where PostDate +interval AddDay day >=curdate();
This will produce the following output −
+----+--------+------------+ | Id | AddDay | PostDate | +----+--------+------------+ | 1 | 20 | 2019-08-04 | | 2 | 7 | 2019-08-20 | +----+--------+------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Fetch records from interval of past 3 days from current date in MySQL and add the corresponding records
- MySQL query to fetch date more recent than 14 days?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL query to fetch the latest date from a table with date records
- Fetch student records whose result declared 12 days before the current date in MYSQL
- Calling NOW() function to fetch current date records in MySQL?
- MySQL query to get the current date records wherein one of the columns displays current date
- Fetch date records comparing with the current date’s day and month in MySQL
- MySQL query to delete a DATE older than 30 days from another date?
- Add 30 days to date in a MySQL table with arrival date records
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- How to select a date less than the current date with MySQL?
- MySQL query to fetch date with year and month?
- MySQL query to count days in date range with start and end date

Advertisements