
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to fetch records before currentdate + 2 weeks?
For this, use the below syntax −
select * from yourTableName where yourColumnName < DATE_ADD(CURDATE(), INTERVAL 2 WEEK);
Note: The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-10-20 | +------------+ 1 row in set (0.00 sec)
Let us first create a table −
mysql> create table DemoTable1607 -> ( -> ShippingDate date -> ) -> ; Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1607 values('2019-10-20'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1607 values('2019-11-04'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1607 values('2019-10-05'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1607 values('2019-09-21'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1607;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2019-10-20 | | 2019-11-04 | | 2019-10-05 | | 2019-09-21 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to fetch records where date is before current date + 2 weeks −
mysql> select * from DemoTable1607 where ShippingDate <DATE_ADD(CURDATE(), INTERVAL 2 WEEK);
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2019-10-20 | | 2019-10-05 | | 2019-09-21 | +--------------+ 3 rows in set (0.06 sec)
- Related Articles
- MySQL query to fetch records wherein timestamp is before 15+ days?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- MySQL query to find a match and fetch records
- MySQL query to fetch records from a range of months?
- MySQL query to fetch records where decimal is a whole number
- MySQL query for text search with LIKE and OR to fetch records
- MySQL query to fetch the latest date from a table with date records
- MySQL query to fetch specific records matched from an array (comma separated values)
- Query MySQL table and fetch rows posted before the last 3 days?
- Fetch student records whose result declared 12 days before the current date in MYSQL
- MySQL query to select date >= current date - 3 weeks?
- MySQL query to insert current date plus specific time?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL query to fetch record by year

Advertisements