Find date record after a particular date from a column with VARCHAR type in MySQL


Let us first create a table. Here, we have set date as VARCHAR −

mysql> create table DemoTable1364
    -> (
    -> ShippingDate varchar(100)
    -> );
Query OK, 0 rows affected (0.87 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1364 values('01-09-2019 12:34:55');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1364 values('01-07-2018 17:10:00');
Query OK, 1 row affected (0.37 sec)
mysql> insert into DemoTable1364 values('24-09-2019 10:31:22');
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable1364 values('20-09-2018 13:00:00');
Query OK, 1 row affected (0.13 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1364;

This will produce the following output −

+---------------------+
| ShippingDate        |
+---------------------+
| 01-09-2019 12:34:55 |
| 01-07-2018 17:10:00 |
| 24-09-2019 10:31:22 |
| 20-09-2018 13:00:00 |
+---------------------+
4 rows in set (0.00 sec)

Here is the query to find date record after a particular date from a column with VARCHAR type −

mysql> select * from DemoTable1364
    -> where str_to_date(ShippingDate,'%d-%m-%Y %H:%i:%s') > str_to_date('2019-09-21 10:31:20', '%Y-%m-%d %H:%i:%s');

This will produce the following output −

+---------------------+
| ShippingDate        |
+---------------------+
| 24-09-2019 10:31:22 |
+---------------------+
1 row in set (0.00 sec)

Updated on: 08-Nov-2019

109 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements