- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Filter query by current date in MySQL
Let us first create a table −
mysql> create table DemoTable(DueDate datetime); Query OK, 0 rows affected (0.94 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-07-10 04:20:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-07-10 05:10:40'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-07-10 09:00:20'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-07-10 10:01:04'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2019-07-10 12:11:10'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-07-10 04:20:00 | | 2019-07-10 05:10:40 | | 2019-07-10 09:00:20 | | 2019-07-10 10:01:04 | | 2019-07-10 12:11:10 | +---------------------+ 5 rows in set (0.00 sec)
Following is the query to filter by current date −
mysql> select *from DemoTable where date(DueDate)=curdate() and time(DueDate) > '04:00:00' and time(DueDate) < '10:00:00';
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-07-10 04:20:00 | | 2019-07-10 05:10:40 | | 2019-07-10 09:00:20 | +---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL query to select date >= current date - 3 weeks?
- MySQL query to get current datetime and only current date
- MySQL query to insert current date plus specific time?
- MySQL query to get the current date records wherein one of the columns displays current date
- Check if the current date falls in a given date range using MySQL query
- MySQL query to retrieve current date from a list of dates
- MySQL query to get the current date from the list of dates
- MySQL query to order by current day and month?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- MySQL query to display databases sorted by creation date?
- Increment date/time value by second with MySQL query?
- MySQL query to order and display difference between dates from the current date
- MySQL - Insert current date/time?
- MySQL query to set current date in the datetime field for all the column values

Advertisements