
- 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
How to check whether now() falls between two specific dates in MySQL?
Here, now() represents the current date. To check whether it falls between two specific dates, you need to use the BETWEEN. Let us first create a table −
mysql> create table DemoTable ( FirstDate datetime, SecondDate datetime ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-04-01','2019-05-02'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('2019-05-28','2019-06-04'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('2016-01-31','2019-03-01'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-----------------------+-----------------------+ | FirstDate | SecondDate | +-----------------------+-----------------------+ | 2019-04-01 00 :00 :00 | 2019-05-02 00 :00 :00 | | 2019-05-28 00 :00 :00 | 2019-06-04 00 :00 :00 | | 2016-01-31 00 :00 :00 | 2019-03-01 00 :00 :00 | +-----------------------+-----------------------+ 3 rows in set (0.00 sec)
Following is the query to check now() falls between two specific dates −
mysql> select *from DemoTable where now() BETWEEN FirstDate AND SecondDate;
Output
+-----------------------+-----------------------+ | FirstDate | SecondDate | +-----------------------+-----------------------+ | 2019-05-28 00 :00 :00 | 2019-06-04 00 :00 :00 | +-----------------------+-----------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to query between two dates in MySQL?
- How to check if one date is between two dates in JavaScript?
- Perform MySQL search between two dates
- How to list all dates between two dates in Excel?
- How to check similarity between two strings in MySQL?
- How to create a vector with dates between two dates in R?
- Select the date records between two dates in MySQL
- How to count days between two dates in Java
- How to search date between two dates in MongoDB?
- How to calculate average between two dates in Excel?
- How to calculate minutes between two dates in JavaScript?
- Find the number of logins between two dates in MySQL
- How to check if two dates are equal in Java 8?
- Display dates after NOW() + 10 days from a MySQL table?
- MySQL query to select all data between range of two dates?

Advertisements