
- 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
Fetch date record that equals today in MySQL
For this, compare the date records with the current date using the CURDATE() method. Let us first create a table −
mysql> create table DemoTable ( RegistrationLastDate datetime ); Query OK, 0 rows affected (0.61 sec)
Let’s say the current date is −
2019-09-03
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-08-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-03 9:50:56'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-09-03'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-09-02'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-09-02 9:50:00'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------------+ | RegistrationLastDate | +----------------------+ | 2019-08-01 00:00:00 | | 2019-09-03 09:50:56 | | 2019-09-03 00:00:00 | | 2019-09-02 00:00:00 | | 2019-09-02 09:50:00 | +----------------------+ 5 rows in set (0.00 sec)
Following is the query to fetch data record that equals today. Here, we are comparing all the records with the current date using the CURDATE() method −
mysql> select *from DemoTable where DATE(RegistrationLastDate)=curdate();
This will produce the following output −
+----------------------+ | RegistrationLastDate | +----------------------+ | 2019-09-03 09:50:56 | | 2019-09-03 00:00:00 | +----------------------+ 2 rows in set (0.01 sec)
- Related Articles
- Display record with today and tomorrow’s date from a column with date record in MySQL
- Order date records and fetch the 2nd ordered record in MySQL
- How to filter dates in MySQL to fetch date record only for a specific month?
- MySQL query to fetch record by year
- MySQL query to select closest date from today?
- Update record on a specific date matching the current date in MySQL
- MySQL Select Date Equal to Today and return results for the same date?
- SELECT MySQL rows where today's date is between two DATE columns?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- MySQL select * and find record with current date
- How to search a record by date in MySQL table?
- Display all records ignoring the current date record in MySQL
- How to get the date between TODAY and TODAY-7”?
- Calling NOW() function to fetch current date records in MySQL?
- MySQL query to fetch date with year and month?

Advertisements