
- 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
Converting date from 'dd/mm/yyyy' to 'yyyymmdd' in MySQL
To convert date from 'dd/mm/yyyy' to 'yyyymmdd', you can use the date_format() method. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Admissiondate varchar(200) ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Admissiondate) values('21/10/2014'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(Admissiondate) values('01/12/2016'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Admissiondate) values('31/01/2017'); Query OK, 1 row affected (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+---------------+ | Id | Admissiondate | +----+---------------+ | 1 | 21/10/2014 | | 2 | 01/12/2016 | | 3 | 31/01/2017 | +----+---------------+ 3 rows in set (0.00 sec)
Following is the query to convert date from 'dd/mm/yyyy' to 'yyyymmdd' −
mysql> select date_format(str_to_date(Admissiondate,'%d/%m/%Y'),'%Y%m%d') from DemoTable;
This will produce the following output −
+-------------------------------------------------------------+ | date_format(str_to_date(Admissiondate,'%d/%m/%Y'),'%Y%m%d') | +-------------------------------------------------------------+ | 20141021 | | 20161201 | | 20170131 | +-------------------------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- MySQL date format DD/MM/YYYY select query?
- How to convert date YYYYMMDD to YY-MM-DD in MySQL query?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- Get date format DD/MM/YYYY with MySQL Select Query?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- Change date format (in DB or output) to dd/mm/yyyy in PHP MySQL?
- How to Convert YYYY-MM-DD to Standard Date in Excel?
- How to format JavaScript date into yyyy-mm-dd format?
- Java Program to format date in mm-dd-yyyy hh:mm:ss format
- Program to reformat date in YYYY-MM-DD format using Python

Advertisements