
- 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 extract date from string in MySQL?
To extract date from the string in MySQL, use SUBSTRING_INDEX(). Let us first create a table −
mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John has got joining date.12/31/2018'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Carol has got joining date.01/11/2019'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Sam will arrive at.12/03/2050'); Query OK, 1 row affected (0.87 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------------------------+ | Title | +---------------------------------------+ | John has got joining date.12/31/2018 | | Carol has got joining date.01/11/2019 | | Sam will arrive at.12/03/2050 | +---------------------------------------+ 3 rows in set (0.00 sec)
Here is the query to extract date from the string in MySQL −
mysql> select substring_index(substring_index(Title,".", -1), ".", 1) from DemoTable;
This will produce the following output −
+----------------------------------------------------------+ | substring_index(substring_index(Title,".", -1), ".", 1) | +----------------------------------------------------------+ | 12/31/2018 | | 01/11/2019 | | 12/03/2050 | +----------------------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to extract date from a string in Python?
- Extract Numeric Date Value from Date Format in MySQL?
- MySQL extract year from date format?
- How to extract the digit part from the string in MySQL?
- How can we extract the Year and Month from a date in MySQL?
- How can we extract a substring from a string in MySQL?
- How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
- How to extract numbers from a string in Python?
- How to extract characters from a string in R?
- Converting a date in MySQL from string field?
- How to extract date from text using Python regular expression?
- Compare DATE string with string from MySQL DATETIME field?
- How to convert a string to date in MySQL?
- How to create JavaScript Date object from date string?
- How to extract multiple integers from a String in Java?

Advertisements