
- 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 select a specific record from MySQL if date is in VARCHAR format?
For this, use STR_TO_DATE(). Let us first create a table −
mysql> create table DemoTable ( DueDate varchar(60) ) ; Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('12-AUG-2016'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('14-AUG-2018'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('24-AUG-2012'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('14-AUG-2012'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | DueDate | +-------------+ | 12-AUG-2016 | | 14-AUG-2018 | | 24-AUG-2012 | | 14-AUG-2012 | +-------------+ 4 rows in set (0.00 sec)
Following is the query to select record from MySQL if date is in VARCHAR format. The STR_TO_DATE() method is used to convert string to date −
mysql> select *from DemoTable where str_to_date(DueDate,'%d-%M-%Y')=str_to_date('14-AUG-2012','%d-%M-%Y');
This will produce the following output −
+-------------+ | DueDate | +-------------+ | 14-AUG-2012 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- How to get a specific column record from SELECT query in MySQL?
- Convert VARCHAR Date to a different format in MySQL?
- Find date record after a particular date from a column with VARCHAR type in MySQL
- Convert VARCHAR data to MySQL date format?
- How to filter a specific month in MySQL when date is in varchar?
- Select date from MySQL and format to text?
- Set a specific Date Format in MySQL?
- How to select record except the lower value record against a specific value in MySQL?
- How to select a random record from a MySQL database?
- Update record on a specific date matching the current date in MySQL
- MySQL select * and find record with current date
- How to filter dates in MySQL to fetch date record only for a specific month?
- How to select date from timestamp in MySQL?
- Best way to change the date format in MySQL SELECT?
- Display record with today and tomorrow’s date from a column with date record in MySQL

Advertisements