 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Perform MySQL SELECT on dates inserted into the table as VARCHAR values
Let us first create a table −
mysql> create table DemoTable ( DueDate varchar(100) ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('21/10/2018'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('18/08/2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('01/12/2012'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('31/01/2016'); 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 | +------------+ | 21/10/2018 | | 18/08/2019 | | 01/12/2012 | | 31/01/2016 | +------------+ 4 rows in set (0.00 sec)
Following is the query to perform SELECT on dates included in the above table as VARCHAR. Here, we are fetching all the date records after the date 2010-01-31 −
mysql> select *from DemoTable where str_to_date(DueDate,'%d/%m/%Y') > '2010-01-31';
This will produce the following output −
+------------+ | DueDate | +------------+ | 21/10/2018 | | 18/08/2019 | | 01/12/2012 | | 31/01/2016 | +------------+ 4 rows in set (0.00 sec)
Advertisements
 