
- 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
How to change date format with DATE_FORMAT() in MySQL?
You can change the MySQL date format with a specific format using DATE_FORMAT(). Following is the syntax −
select date_format(yourColumnName,yourFormatSpecifier) from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2016-01-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2018-05-24'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-12-31'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2016-01-21 | | 2018-05-24 | | 2019-12-31 | +--------------+ 3 rows in set (0.00 sec)
Following is the query to implement DATE_FORMAT() in MySQL query and set date format −
mysql> select date_format(ShippingDate,'%d/%m/%Y') from DemoTable;
This will produce the following output −
+--------------------------------------+ | date_format(ShippingDate,'%d/%m/%Y') | +--------------------------------------+ | 21/01/2016 | | 24/05/2018 | | 31/12/2019 | +--------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Change date format in MongoDB
- How to convert Python date format to 10-digit date format for mysql?
- Change the curdate() (current date) format in MySQL
- How to change date time format in HTML5?
- How to change American date format in Excel?
- PHP program to change date format
- Replace date format with MySQL STR_TO_DATE
- Convert MySQL Unix-Timestamp format to date format?
- Best way to change the date format in MySQL SELECT?
- How to convert US date format to MySQL format in INSERT query?
- Format date to display month names with the entire date in MySQL?
- PHP program to change the date format
- How to update the date format in MySQL?
- How to convert a date format in MySQL?
- Change date format in MySQL database table to d/m/y

Advertisements