
- 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
Get date format DD/MM/YYYY with MySQL Select Query?
Use the STR_TO_DATE() function from MySQL to set a date format for displaying DD/MM/YYYY date. The syntax is as follows −
SELECT STR_TO_DATE(yourColumnName,’%d/%m/%Y) as anyVariableName from yourTableName.
To understand the above syntax, let us create a table −
mysql> create table DateFormatDemo −> ( −> IssueDate varchar(100) −> ); Query OK, 0 rows affected (0.54 sec)
Inserting some string dates into the table. The query to insert date is as follows −
mysql> insert into DateFormatDemo values('26/11/2018'); Query OK, 1 row affected (0.14 sec) mysql> insert into DateFormatDemo values('27/11/2018'); Query OK, 1 row affected (0.18 sec) mysql> insert into DateFormatDemo values('2/12/2018'); Query OK, 1 row affected (0.13 sec) mysql> insert into DateFormatDemo values('3/12/2018'); Query OK, 1 row affected (0.14 sec)
Now you can display all dates which I have inserted above. The query is as follows −
mysql> select *from DateFormatDemo;
The following is the output −
+------------+ | IssueDate | +------------+ | 26/11/2018 | | 27/11/2018 | | 2/12/2018 | | 3/12/2018 | +------------+ 4 rows in set (0.00 sec)
You can implement the syntax we discussed in the beginning to convert string to date format. The query is as follows −
mysql> select STR_TO_DATE(IssueDate, '%d/%m/%Y') StringToDateFormatExample from DateFormatDemo;
The following is the output −
+---------------------------+ | StringToDateFormatExample | +---------------------------+ | 2018-11-26 | | 2018-11-27 | | 2018-12-02 | | 2018-12-03 | +---------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL date format DD/MM/YYYY select query?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- How to format JavaScript date into yyyy-mm-dd format?
- Java Program to format date in mm-dd-yyyy hh:mm:ss format
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- Accepting date strings (MM-dd-yyyy format) using Java regex?
- Program to reformat date in YYYY-MM-DD format using Python
- Change date format (in DB or output) to dd/mm/yyyy in PHP MySQL?
- How to insert mm/dd/yyyy format dates in MySQL?
- How to format a string to date in as dd-MM-yyyy using java?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- How to convert MM/YY to YYYY-MM-DD in MYSQL?

Advertisements