
- 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
Fastest way to search for a date from the date records in MySQL
The fastest and easiest way is to use the MySQL BETWEEN keyword. Let us first create a −
mysql> create table DemoTable1413 -> ( -> EmployeeName varchar(20), -> EmployeeJoiningDate datetime -> ); Query OK, 0 rows affected (0.45 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1413 values('Chris','2018-09-28 11 :10 :50'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1413 values('David','2019-09-28 11:10:50'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1413 values('Mike','2019-09-29 12:40:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1413 values('Carol','2019-09-28 12:06:10'); Query OK, 1 row affected (0.08 sec)
Display all records from the table using select −
mysql> select * from DemoTable1413;
This will produce the following output −
+--------------+---------------------+ | EmployeeName | EmployeeJoiningDate | +--------------+---------------------+ | Chris | 2018-09-28 11:10:50 | | David | 2019-09-28 11:10:50 | | Mike | 2019-09-29 12:40:00 | | Carol | 2019-09-28 12:06:10 | +--------------+---------------------+ 4 rows in set (0.00 sec)
Here is the query to search for date records between dates −
mysql> select * from DemoTable1413 -> where EmployeeJoiningDate between '2019-09-28' and '2019-09-28 23:59:59' -> limit 1;
This will produce the following output −
+--------------+---------------------+ | EmployeeName | EmployeeJoiningDate | +--------------+---------------------+ | David | 2019-09-28 11:10:50 | +--------------+---------------------+ 1 row in set (0.03 sec)
- Related Articles
- The easiest way to insert date records in MySQL?
- Search records on the basis of date in MySQL?
- Comparison of varchar date records from the current date in MySQL
- MySQL query to fetch the latest date from a table with date records
- How to compare the first date and the last date from a MySQL column with date records?
- How to find last date from records with date values in MySQL?
- Find the difference between current date and the date records from a MySQL table
- How to search for a date in MySQL timestamp field?
- How to display coming Sunday's date for all the date records in MySQL?
- How to change the date in a table with date records with MySQL?
- Condition to check for due date and current date records in MySQL where clause
- How to subtract seconds from all the date records in a MySQL column?
- Add 30 days to date in a MySQL table with arrival date records
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Display distinct dates in MySQL from a column with date records

Advertisements