- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the date between TODAY and TODAY-7”?
152 Lectures 16 hours
87 Lectures 5.5 hours
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;
+------------+ | 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);
+------------+ | LoginDate | +------------+ | 2019-05-27 | | 2019-06-01 | +------------+ 2 rows in set (0.06 sec)
- How to get today's date in Java8?
- MySQL Select Date Equal to Today and return results for the same date?
- MySQL query to select closest date from today?
- Get the Day of the Week from Today's Date in Java
- SELECT MySQL rows where today's date is between two DATE columns?
- Fetch date record that equals today in MySQL
- Get documents expired before today in MongoDB?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- Display today’s date in Java with SimpleDateFormat
- MySQL query to select date from 00:00 to today’s date
- How to return today's records using DATE from DATETIME Field?
- MySQL Select to get users who have logged in today?