
- 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
Display month names and year from a column with date records with MySQL
Let us first create a −
mysql> create table DemoTable1619 -> ( -> ArrivalTime datetime -> ); Query OK, 0 rows affected (0.45 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1619 values(now()); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable1619 values(curdate()); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1619 values('2019-12-31'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select −
mysql> select * from DemoTable1619;
This will produce the following output −
+---------------------+ | ArrivalTime | +---------------------+ | 2019-10-20 15:02:12 | | 2019-10-20 00:00:00 | | 2019-12-31 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
Following is the query to convert datetime to get month name in MySQL −
mysql> select date_format(ArrivalTime,'%M %Y') from DemoTable1619;
This will produce the following output −
+----------------------------------+ | date_format(ArrivalTime,'%M %Y') | +----------------------------------+ | October 2019 | | October 2019 | | December 2019 | +----------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Display distinct dates in MySQL from a column with date records
- Format date to display month names with the entire date in MySQL?
- Get Nth weekday of the month from a column with DATE records in MySQL
- MySQL query to fetch date with year and month?
- Display record with today and tomorrow’s date from a column with date record in MySQL
- MySQL SELECT query to return records with specific month and year
- How to compare the first date and the last date from a MySQL column with date records?
- Group by one column and display corresponding records from another column with a separator in MySQL
- MySQL query to subtract date records with week day and display the weekday with records
- MySQL query to display the count of distinct records from a column with duplicate records
- How to compare Year, Month and Day in a MySQL query and display matching records
- Display records from the current date till rest of the same month in MySQL?
- How to display first day and last day of the month from date records in MySQL?
- How can fetch records from specific month and year in a MySQL table?
- Create date from day, month, year fields in MySQL?

Advertisements