
- 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
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)
- Related Articles
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL query to delete a DATE older than 30 days from another date?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- MySQL query to fetch date with year and month?
- MySQL query to fetch records wherein timestamp is before 15+ days?
- How to delete rows older than 14 days in MySQL?
- MySQL query to fetch the latest date from a table with date records
- MySQL query to count days in date range with start and end date
- MySQL query to delete all rows older than 30 days?
- Query MySQL table and fetch rows posted before the last 3 days?
- MySQL query to find expiry date (record) from the next 2 days?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL query to find a value appearing more than once?
- Fetch student records whose result declared 12 days before the current date in MYSQL
- MySQL add days to a date?

Advertisements