
- 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 SELECT last few days?
To select last few days, use DATE_ADD() function in MySQL. The syntax is as follows −
select date_add(curdate(),interval - anyIntgegerValue day);
Or you can DATE_SUB() from MySQL.
select date_sub(curdate(),interval anyIntgegerValue day);
Or you can use the following syntax −
select curdate() - interval anyIntgegerValue day;
Here is the example of all syntaxes shown above to select last few days.
Case 1 − Use of DATE_ADD() function
The query is as follows −
mysql> select date_add(curdate(),interval -6 day);
Here is the output −
+-------------------------------------+ | date_add(curdate(),interval -6 day) | +-------------------------------------+ | 2018-11-20 | +-------------------------------------+ 1 row in set (0.00 sec)
Case 2 − Use of DATE_SUB() function
The query is as follows −
mysql> select date_sub(curdate(),interval 6 day);
Here is the output −
+------------------------------------+ | date_sub(curdate(),interval 6 day) | +------------------------------------+ | 2018-11-20 | +------------------------------------+ 1 row in set (0.00 sec)
Case 3 − Use of minus (-) symbol
The query is as follows −
mysql> select curdate()-interval 6 day;
Here is the output −
+--------------------------+ | curdate()-interval 6 day | +--------------------------+ | 2018-11-20 | +--------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to select last row in MySQL?
- Select text after last slash in MySQL?
- Get the last days of all the months in MySQL?
- How to select last 10 rows from MySQL?
- Select last day of current year in MySQL?
- How to select last two rows in MySQL?
- SELECT last entry without using LIMIT in MySQL?
- Select last record and update it in MySQL?
- Query MySQL table and fetch rows posted before the last 3 days?
- Select last 20 records ordered in ascending order in MySQL?
- How to select first and last data row from a MySQL result?
- How to select first and last row record using LIMIT in MySQL?
- Select only 5 random rows in the last 50 entries With MySQL?
- Discuss few characteristics of MySQL
- How do you select from MySQL where last value in a string = x?

Advertisements