
- 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
Check if the current date falls in a given date range using MySQL query
Let us first create a table −
mysql> create table DemoTable1448 -> ( -> StartDate date, -> EndDate date -> ); Query OK, 0 rows affected (0.46 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1448 values('2019-01-21','2019-03-22'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1448 values('2019-04-05','2019-10-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1448 values('2019-10-01','2019-10-29'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1448 values('2018-12-31','2019-12-31'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1448;
This will produce the following output −
+------------+------------+ | StartDate | EndDate | +------------+------------+ | 2019-01-21 | 2019-03-22 | | 2019-04-05 | 2019-10-10 | | 2019-10-01 | 2019-10-29 | | 2018-12-31 | 2019-12-31 | +------------+------------+ 4 rows in set (0.00 sec)
Let’s say the current date is −
2019-10-05
Following is the query to check if the current date falls in a given date range −
mysql> select (curdate() >=StartDate and curdate() <=EndDate) as DateInRange from DemoTable1448;
This will produce the following output −
+-------------+ | DateInRange | +-------------+ | 0 | | 1 | | 1 | | 1 | +-------------+ 4 rows in set (0.04 sec)
- Related Articles
- MySQL query to select date >= current date - 3 weeks?
- Filter query by current date in MySQL
- Ignoring the year in MySQL Query with date range?
- MySQL query to count days in date range with start and end date
- MySQL query to get the current date records wherein one of the columns displays current date
- MySQL query to get current datetime and only current date
- MySQL query to insert current date plus specific time?
- Condition to check for due date and current date records in MySQL where clause
- MySQL query to retrieve current date from a list of dates
- MySQL date comparison to fetch dates between a given range?
- Update record on a specific date matching the current date in MySQL
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MongoDB query to get date records in a range
- MySQL date column auto fill with current date?
- MySQL query to get the current date from the list of dates

Advertisements