
- 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
MySQL DATE_FORMAT '%M' is used for short month?
The %M Date Format is not used for displaying short months like Jan for January, Feb for February, etc. You need to use DATE_FORMAT() function with %b format for short month. The syntax is as follows:
SELECT DATE_FORMAT(yourColumnName, '%d-%b-%y') AS anyVariableName FROM yourTableName;
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table DateFormatMonthDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> ShippingDate date, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command. The query to insert record is as follows:
mysql> insert into DateFormatMonthDemo(ShippingDate) values('2019-05-21'); Query OK, 1 row affected (0.23 sec) mysql> insert into DateFormatMonthDemo(ShippingDate) values('2015-05-23'); Query OK, 1 row affected (0.14 sec) mysql> insert into DateFormatMonthDemo(ShippingDate) values('2019-11-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DateFormatMonthDemo(ShippingDate) values('2017-12-24'); Query OK, 1 row affected (0.15 sec) mysql> insert into DateFormatMonthDemo(ShippingDate) values('2016-01-13'); Query OK, 1 row affected (0.19 sec) mysql> insert into DateFormatMonthDemo(ShippingDate) values('2015-02-22'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement. The query is as follows:
mysql> select *from DateFormatMonthDemo;
+----+--------------+ | Id | ShippingDate | +----+--------------+ | 1 | 2019-05-21 | | 2 | 2015-05-23 | | 3 | 2019-11-01 | | 4 | 2017-12-24 | | 5 | 2016-01-13 | | 6 | 2015-02-22 | +----+--------------+ 6 rows in set (0.00 sec)
Here is the query to display short month names:
mysql> select DATE_FORMAT(ShippingDate, '%d-%b-%y') AS DateDemo from DateFormatMonthDemo;
The following is the output:
+-----------+ | DateDemo | +-----------+ | 21-May-19 | | 23-May-15 | | 01-Nov-19 | | 24-Dec-17 | | 13-Jan-16 | | 22-Feb-15 | +-----------+ 6 rows in set (0.04 sec)
- Related Articles
- Short Date ("d") Format Specifier
- Short Length format for Date with Java MessageFormat class
- Format MySQL date and convert to year-month-day
- Format date to display month names with the entire date in MySQL?
- Format Month in M format in Java
- Month ("M", "m") Format Specifier in C#
- How to convert Python date format to 10-digit date format for mysql?
- C# General Date Short Time ("g") Format Specifier
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- Full Date Short Time ("f") Format Specifier in C#
- Change date format in MySQL database table to d/m/y
- What are different date format characters used by MySQL DATE_FORMAT() function?
- Convert MySQL Unix-Timestamp format to date format?
- Java Program to display date with day name in short format
- MySQL extract year from date format?

Advertisements