
- 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
Selecting records 15 days before today in MySQL?
For this, you can use the concept of INTERVAL and DATE_SUB(). Let us first create a table −
mysql> create table DemoTable1845 ( ArrivalDate date ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1845 values('2019-12-02'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1845 values('2019-11-18'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1845 values('2019-12-18'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1845 values('2019-12-25'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1845 values('2019-11-15'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1845;
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2019-12-02 | | 2019-11-18 | | 2019-12-18 | | 2019-12-25 | | 2019-11-15 | +-------------+ 5 rows in set (0.00 sec)
The current date is as follows −
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-12-02 20:47:05 | +---------------------+ 1 row in set (0.00 sec)
Here is the query to fetch records 15 days before today −
mysql> select * from DemoTable1845 where ArrivalDate < DATE_SUB(NOW(), INTERVAL 15 DAY);
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2019-11-15 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to fetch records wherein timestamp is before 15+ days?
- Fetch student records whose result declared 12 days before the current date in MYSQL
- Get documents expired before today in MongoDB?
- MySQL query to fetch records before currentdate + 2 weeks?
- Fetch datetime row from exactly past 7 days records in MySQL
- Selecting records within a range and with a condition set on two columns in MySQL?
- Get two days data (today and yesterday) from a MySQL table with timestamp values
- Add 30 days to date in a MySQL table with arrival date records
- Fetch records from interval of past 3 days from current date in MySQL and add the corresponding records
- Query MySQL table and fetch rows posted before the last 3 days?
- Selecting a single row in MySQL?
- How to get the records of the last two days from the current date in MySQL?
- Selecting Random Result from MySQL?
- How to look beautiful in 15 days?
- Selecting random entry from MySQL Database?

Advertisements