

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- The easiest way to insert date records in MySQL?
- Search records on the basis of date in MySQL?
- MySQL query to fetch the latest date from a table with date records
- Comparison of varchar date records from the current date in MySQL
- How to compare the first date and the last date from a MySQL column with date records?
- Find the difference between current date and the date records from a MySQL table
- How to find last date from records with date values in MySQL?
- How to search for a date in MySQL timestamp field?
- How to change the date in a table with date records with MySQL?
- How to display coming Sunday's date for all the date records in 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?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Add 30 days to date in a MySQL table with arrival date records
- How to get the difference between date records and the current date in MySQL?
Advertisements