

- 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
How to compare Year, Month and Day in a MySQL query and display matching records
For this, you can use DATE(). Let us first create a table −
mysql> create table DemoTable864(DueDateTime timestamp); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable864 values('2019-01-10 12 −34 −55'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable864 values('2016-12-11 11 −12 −00'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable864 values('2015-04-01 10 −00 −00'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable864 values('2017-05-20 04 −40 −10'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable864;
This will produce the following output −
+---------------------+ | DueDateTime | +---------------------+ |2019-01-10 12 −34 −55| |2016-12-11 11 −12 −00| |2015-04-01 10 −00 −00| |2017-05-20 04 −40 −10| +---------------------+ 4 rows in set (0.00 sec)
Following is the query to compare year, month and day −
mysql> select *from DemoTable864 where date(DueDateTime)='2015-04-01';
This will produce the following output −
+-----------------------+ | DueDateTime | +-----------------------+ | 2015-04-01 10 −00 −00 | +-----------------------+ 1 row in set (0.04 sec)
- Related Questions & Answers
- Filter the records of current day, month and year in MySQL?
- MySQL SELECT query to return records with specific month and year
- How to display first day and last day of the month from date records in MySQL?
- Format MySQL date and convert to year-month-day
- Display month names and year from a column with date records with MySQL
- MySQL to fetch records based on a specific month and year?
- MongoDB query to search date records using only Month and Day
- MySQL query to fetch date with year and month?
- MySQL query to order by current day and month?
- Compare only day and month with date field in MySQL?
- MySQL query to subtract date records with week day and display the weekday with records
- How to get a Date from year, month and day in Java?
- How can fetch records from specific month and year in a MySQL table?
- How to get current day, month and year in Java 8?
- Group month and year in MySQL?
Advertisements