
- 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
Selecting rows that are older than current date in MySQL?
Let’s say the current date is 2019-08-03. Now, we will see an example and create a table −
mysql> create table DemoTable840(DueDate datetime); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable840 values('2019-08-9'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable840 values('2019-07-5'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable840 values('2019-08-10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable840 values('2019-07-13'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable840;
This will produce the following output −
+-----------------------+ | DueDate | +-----------------------+ | 2019-08-09 00 −00 −00 | | 2019-07-05 00 −00 −00 | | 2019-08-10 00 −00 −00 | | 2019-07-13 00 −00 −00 | +-----------------------+ 4 rows in set (0.00 sec)
Following is the query to select rows older than the current date in MySQL −
mysql> select *from DemoTable840 where DueDate < NOW();
This will produce the following output −
+-----------------------+ | DueDate | +-----------------------+ | 2019-07-05 00 −00 −00 | | 2019-07-13 00 −00 −00 | +-----------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Find posts that are older than current date in MongoDB?
- Deleting all rows older than 5 days in MySQL
- How to select rows in MySQL that are >= 1 DAY from the current date?
- How to delete rows older than 14 days in MySQL?
- MySQL query to select rows older than a week?
- Fetching rows updated at timestamp older than 1 day in MySQL?
- MySQL query to delete all rows older than 30 days?
- MySQL query to delete a DATE older than 30 days from another date?
- Compare date when the AdmissionDate is less than the current date in MySQL
- How to select a date less than the current date with MySQL?
- Selecting rows using the ENUM field in MySQL
- MySQL: selecting rows where a column is null?
- Delete records where timestamp older than 5 minutes in MySQL?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL - Insert current date/time?

Advertisements