- 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
MySQL search results by month in format 2015-07-01 11:15:30?
Use MONTH() and YEAR() for this. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(ShippingDate) values('2019-01-21 10:40:21'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ShippingDate) values('2015-07-01 11:15:30'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ShippingDate) values('2012-12-31 10:45:56'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+---------------------+ | Id | ShippingDate | +----+---------------------+ | 1 | 2019-01-21 10:40:21 | | 2 | 2015-07-01 10:40:20 | | 3 | 2012-12-31 10:45:56 | +----+---------------------+ 3 rows in set (0.00 sec)
Following is the query to search results by MONTH and YEAR −
mysql> select *from DemoTable where MONTH(ShippingDate)=7 and YEAR(ShippingDate)=2015;
This will produce the following output −
+----+---------------------+ | Id | ShippingDate | +----+---------------------+ | 2 | 2015-07-01 11:15:30 | +----+---------------------+ 1 row in set (0.03 sec)
- Related Articles
- Order dates in MySQL with the format “01 August 2019”?
- Format hour in kk (01-24) format in Java
- C++11 features in Visual Studio 2015
- Sort search results based on substring position in MySQL
- Display Seconds in ss format (01, 02) in Java
- Format Month in M format in Java
- Format Month in MM format in Java
- Format MySQL date and convert to year-month-day
- Java Program to format Month in MMMM format
- In a particular month, a shopkeeper incurs a loss of Rs. 15, by losing 30 paise per pencil. Calculate the number of pencil sold in this month.
- Display hour in hh (01-12 in AM/PM) format in Java
- Format date to display month names with the entire date in MySQL?
- Convert PHP variable “11:00 AM” to MySQL time format?
- How to MySQL SELECT by month?
- Extract the month and year in the following format: “mm-yyyy” (month year) along with all columns in MySQL?

Advertisements