
- 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
How to get the date between TODAY and TODAY-7”?
To get the date between dates, you need to use. Here, we are getting the dates between today and today-7 days −
select *from yourTableName where DATE(yourColumnName) > (NOW() - INTERVAL 7 DAY);
Note : Let’s say the current date is '2019-06-02’ Let us first create a table.
mysql> create table DemoTable ( LoginDate date ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2018-03-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-05-22'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-05-27'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-06-01'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+------------+ | LoginDate | +------------+ | 2018-03-21 | | 2019-05-22 | | 2019-05-27 | | 2019-06-01 | +------------+ 4 rows in set (0.00 sec)
Following is the query to display dates between today and today – 7 days −
mysql> select *from DemoTable where DATE(LoginDate) > (NOW() - INTERVAL 7 DAY);
Output
+------------+ | LoginDate | +------------+ | 2019-05-27 | | 2019-06-01 | +------------+ 2 rows in set (0.06 sec)
- Related Articles
- How to get today's date in Java8?
- How to subtract date from today's date in JavaScript?
- MySQL Select Date Equal to Today and return results for the same date?
- Get the Day of the Week from Today's Date in Java
- MySQL query to select closest date from today?
- SELECT MySQL rows where today's date is between two DATE columns?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- Finding the nth day from today - JavaScript (JS Date)
- Fetch date record that equals today in MySQL
- How to return today's records using DATE from DATETIME Field?
- Get documents expired before today in MongoDB?
- Display record with today and tomorrow’s date from a column with date record in MySQL
- MySQL Select to get users who have logged in today?
- How to get the last business day of previous month based on today in Excel?
- Where is JavaScript Today?

Advertisements