- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to select date >= current date - 3 weeks?
Use the concept of DATE_SUB(). Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ArrivalDate datetime ); Query OK, 0 rows affected (1.02 sec)
Note: Let’s say the current date is 2019-06-08
Insert some records in the table using insert command −
mysql> insert into DemoTable(ArrivalDate) values('2019-05-15'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-06-08'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-05-20'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-05-12'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+---------------------+ | Id | ArrivalDate | +----+---------------------+ | 1 | 2019-05-15 00:00:00 | | 2 | 2019-06-08 00:00:00 | | 3 | 2019-05-20 00:00:00 | | 4 | 2019-05-12 00:00:00 | +----+---------------------+ 4 rows in set (0.00 sec)
Here is the query to select the dates, which are greater than equal to current date - 3 weeks −
mysql> select ArrivalDate from DemoTable where ArrivalDate> DATE_SUB(curdate(),INTERVAL 3 WEEK);
Output
+---------------------+ | ArrivalDate | +---------------------+ | 2019-06-08 00:00:00 | | 2019-05-20 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Select dates between current date and 3 months from the current date in MySQL?
- MySQL query to select date from 00:00 to today’s date
- MySQL query to select date from timestamp?
- How to select a date less than the current date with MySQL?
- MySQL query to select closest date from today?
- MySQL query to get current datetime and only current date
- Filter query by current date in MySQL
- Add two weeks to a date in MySQL?
- MySQL query to get the current date records wherein one of the columns displays current date
- MySQL select * and find record with current date
- MySQL query to insert current date plus specific time?
- MySQL query to select records with a particular date?
- MySQL date format DD/MM/YYYY select query?
- How to select a query for a selected day(2010-11-04) to current date using MySQL?

Advertisements