STR_TO_DATE as column, but column not found?


You can use having clause. Let us first create a table −

mysql> create table DemoTable
   -> (
   -> AdmissionDate varchar(100)
   -> );
Query OK, 0 rows affected (0.55 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('10/12/2017');
Query OK, 1 row affected (0.18 sec)

mysql> insert into DemoTable values('01/11/2018');
Query OK, 1 row affected (0.12 sec)

mysql> insert into DemoTable values('31/01/2019');
Query OK, 1 row affected (0.18 sec)

mysql> insert into DemoTable values('09/06/2019');
Query OK, 1 row affected (0.16 sec)

mysql> insert into DemoTable values('19/04/2019');
Query OK, 1 row affected (0.23 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+---------------+
| AdmissionDate |
+---------------+
| 10/12/2017    |
| 01/11/2018    |
| 31/01/2019    |
| 09/06/2019    |
| 19/04/2019    |
+---------------+
5 rows in set (0.00 sec)

Following is the query to STR_TO_DATE as column −

mysql> select STR_TO_DATE(AdmissionDate, '%d/%m/%Y') as newDate from DemoTable
   -> having newDate >= '2019-01-01';

Output

+------------+
| newDate    |
+------------+
| 2019-01-31 |
| 2019-06-09 |
| 2019-04-19 |
+------------+
3 rows in set (0.00 sec)
raja
Published on 10-Jul-2019 16:26:21
Advertisements