
- 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 records wherein timestamp is before 15+ days?
Let us first create a table −
mysql> create table DemoTable -> ( -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.91 sec)
Insert some records in the table using insert command. Let’s say the current date is 2019-07-03 −
mysql> insert into DemoTable values('2019-07-03'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-06-20'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2019-06-15'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2018-06-11'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2018-06-01'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------+ | ArrivalDate | +---------------------+ | 2019-07-03 00:00:00 | | 2019-06-20 00:00:00 | | 2019-06-15 00:00:00 | | 2018-06-11 00:00:00 | | 2018-06-01 00:00:00 | +---------------------+ 5 rows in set (0.00 sec)
Following is the query to fetch records wherein timestamp is 15+ days ago −
mysql> select *from DemoTable where ArrivalDate < date_sub(now(), interval 15 day) order by ArrivalDate DESC;
Output
This will produce the following output −
+---------------------+ | ArrivalDate | +---------------------+ | 2019-06-15 00:00:00 | | 2018-06-11 00:00:00 | | 2018-06-01 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL query to fetch records before currentdate + 2 weeks?
- Selecting records 15 days before today in MySQL?
- Query MySQL table and fetch rows posted before the last 3 days?
- Fetch student records whose result declared 12 days before the current date in MYSQL
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL query to fetch records where decimal is a whole number
- MySQL query to find a match and fetch records
- MySQL query to fetch date more recent than 14 days?
- MySQL query to fetch records from a range of months?
- Fetch datetime row from exactly past 7 days records in MySQL
- MySQL query to get the current date records wherein one of the columns displays current date
- MySQL query for text search with LIKE and OR to fetch records
- MySQL query to fetch the latest date from a table with date records
- MySQL query to fetch specific records matched from an array (comma separated values)
- Fetch records from a subdocument array wherein id begins from 234 in MongoDB

Advertisements