Fetch Records After a Specific Date in Different Format Using Unix Timestamp in MySQL



For this, you can use STR_TO_DATE(), since we have date records in the following format: 21/11/2019.

Let us first create a table −

mysql> create table DemoTable1808
     (
     AdmissionDate varchar(20)
     );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1808 values('21/11/2019');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1808 values('01/01/2018');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1808 values('26/09/2017');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1808;

This will produce the following output −

+---------------+
| AdmissionDate |
+---------------+
| 21/11/2019    |
| 01/01/2018    |
| 26/09/2017    |
+---------------+
3 rows in set (0.00 sec)

Here is the query to fetch records after a particular date −

mysql> select * from DemoTable1808
   where str_to_date(AdmissionDate,'%d/%m/%Y') > '2018-12-31';

This will produce the following output −

+---------------+
| AdmissionDate |
+---------------+
| 21/11/2019    |
+---------------+
1 row in set (0.00 sec)
Updated on: 2020-02-25T13:12:18+05:30

284 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements