
- 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 parse date in MySQL?
Parse date in MySQL with the help of STR_TO_DATE() function. The syntax is as follows −
select str_to_date(yourColumName,’format’) as anyVariableName from yourTableName;
The format in the above syntax is '%d-%b-%y'.
Now to understand the above function, let us create a table. The following is the query to create a table −
mysql> create table ParseDateDemo −> ( −> yourDate varchar(200) −> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table with the help of select statement. The query is as follows −
mysql> insert into ParseDateDemo values('10-Nov-18'); Query OK, 1 row affected (0.11 sec) mysql> insert into ParseDateDemo values('15-Nov-18'); Query OK, 1 row affected (0.17 sec) mysql> insert into ParseDateDemo values('10-Dec-18'); Query OK, 1 row affected (0.14 sec) mysql> insert into ParseDateDemo values('10-Aug-17'); Query OK, 1 row affected (0.14 sec)
Display records from the table with the help of select statement. The query is as follows −
mysql> select *from ParseDateDemo;
The following is the output −
+-----------+ | yourDate | +-----------+ | 10-Nov-18 | | 15-Nov-18 | | 10-Dec-18 | | 10-Aug-17 | +-----------+ 4 rows in set (0.00 sec)
The following is the query to parse date in MySQL −
mysql> select str_to_date(yourDate,'%d-%b-%y') as DateNumber from ParseDateDemo;
Here is the output −
+------------+ | DateNumber | +------------+ | 2018-11-10 | | 2018-11-15 | | 2018-12-10 | | 2017-08-10 | +------------+ 4 rows in set (0.02 sec)
- Related Articles
- How to parse date sting to date in Java?
- How to parse date in JSP?
- How to parse Date strings in Golang?
- Format and Parse Date in Java
- Java Program to parse date and time
- Parse string date value input in Java
- Parse string date time value input in Java
- How to convert a MySQL date to JavaScript date?
- Java Program to parse string date value with default format
- How to insert date in single quotes with MySQL date formats?
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- How to insert current date/time in MySQL?
- How to select date from timestamp in MySQL?
- How to update the date format in MySQL?
- How to convert a date format in MySQL?

Advertisements