- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
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)
Advertisements