
- 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 records comparing with the current date’s day and month in MySQL
For this, use MONTH() and DAY(). Let us first create a −
mysql> create table DemoTable1429 -> ( -> AnniversaryDate date -> );
Insert some records in the table using insert −
mysql> insert into DemoTable1429 values('2019-09-29'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1429 values('2018-09-27'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1429 values('2016-09-28'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1429 values('2015-09-29'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select −
mysql> select * from DemoTable1429;
This will produce the following output −
+-----------------+ | AnniversaryDate | +-----------------+ | 2019-09-29 | | 2018-09-27 | | 2016-09-28 | | 2015-09-29 | +-----------------+ 4 rows in set (0.00 sec)
The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-09-29 | +------------+ 1 row in set (0.00 sec)
Here is the query to fetch date records comparing with current date’s day and month −
mysql> select * from DemoTable1429 -> where month(AnniversaryDate)=month(curdate()) -> and day(AnniversaryDate)=day(curdate());
This will produce the following output −
+-----------------+ | AnniversaryDate | +-----------------+ | 2019-09-29 | | 2015-09-29 | +-----------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- Calling NOW() function to fetch current date records in MySQL?
- MySQL query to fetch date with year and month?
- How can we fetch month and day from a given date in MySQL?
- How to display first day and last day of the month from date records in MySQL?
- Compare only day and month with date field in MySQL?
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- MySQL query to fetch the latest date from a table with date records
- Grab where current date and the day before with MySQL?
- Filter the records of current day, month and year in MySQL?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Display records from the current date till rest of the same month in MySQL?
- Fetch records from interval of past 3 days from current date in MySQL and add the corresponding records
- Comparison of varchar date records from the current date in MySQL
- MongoDB query to search date records using only Month and Day

Advertisements