 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 fetch date more recent than 14 days?
Let us first create a −
mysql> create table DemoTable1392 -> ( -> ArrivalDate date -> ); Query OK, 0 rows affected (0.43 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1392 values('2019-09-10'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable1392 values('2019-09-26'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1392 values('2019-09-12'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1392 values('2018-09-20'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable1392 values('2019-10-11'); Query OK, 1 row affected (0.11 sec) Display all records from the table using select −
mysql> select * from DemoTable1392;
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2019-09-10 | | 2019-09-26 | | 2019-09-12 | | 2018-09-20 | | 2019-10-11 | +-------------+ 5 rows in set (0.00 sec)
The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-09-26 | +------------+ 1 row in set (0.00 sec)
Here is the query to fetch date more recent than 14 days −
mysql> select * from DemoTable1392 -> where ArrivalDate > date_sub(curdate(), interval 14 day);
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2019-09-26 | | 2019-10-11 | +-------------+ 2 rows in set (0.03 sec)
Advertisements
 