
- 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 convert MM/YY to YYYY-MM-DD with a specific day in MySQL?
To convert, use STR_TO_DATE(), as in the below syntax. Concatenate the day value with CONCAT() −
select str_to_date(concat('yourDateValue/', yourColumnName), '%d/%m/%y') as anyAliasName from yourTableName;
Let us create a table −
mysql> create table demo46 −> ( −> id int not null auto_increment primary key, −> short_date varchar(20) −> ); Query OK, 0 rows affected (0.60 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo46(short_date) values('09/18'); Query OK, 1 row affected (0.08 sec) mysql> insert into demo46(short_date) values('12/20'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo46(short_date) values('11/20'); Query OK, 1 row affected (0.20 sec)
Display records from the table using select statement −
mysql> select *from demo46;
This will produce the following output −
+----+------------+ | id | short_date | +----+------------+ | 1 | 09/18 | | 2 | 12/20 | | 3 | 11/20 | +----+------------+ 3 rows in set (0.00 sec)
Following is the query to convert MM/YY to YYYY-MM-DD in MySQL.
mysql> select str_to_date(concat('24/', short_date), '%d/%m/%y') as Convert_In_Full_Date −> from demo46;
This will produce the following output −
+----------------------+ | Convert_In_Full_Date | +----------------------+ | 2018−09−24 | | 2020−12−24 | | 2020−11−24 | +----------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- Convert MM/DD/YY to Unix timestamp in MySQL?
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- How to convert date YYYYMMDD to YY-MM-DD in MySQL query?
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- How to Convert YYYY-MM-DD to Standard Date in Excel?
- How to insert mm/dd/yyyy format dates in MySQL?
- How to convert Python date string mm/dd/yyyy to datetime?
- MySQL date format DD/MM/YYYY select query?
- Get date format DD/MM/YYYY with MySQL Select Query?
- How to format JavaScript date into yyyy-mm-dd format?

Advertisements