Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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
