- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Display record with most recent time in MySQL
You can use ORDER BY STR_TO_DATE(). Let us first create a table −
mysql> create table DemoTable -> ( -> DueTime varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('7:30AM'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('9:00PM'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('11:00PM'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output−
+---------+ | DueTime | +---------+ | 7:30AM | | 9:00PM | | 11:00PM | +---------+ 3 rows in set (0.00 sec)
Here is the query to fetch records with most recent time −
mysql> select * from DemoTable -> order by str_to_date(DueTime, '%h:%i%p') desc limit 1;
This will produce the following output −
+---------+ | DueTime | +---------+ | 11:00PM | +---------+ 1 row in set (0.00 sec)
- Related Articles
- Display record with today and tomorrow’s date from a column with date record in MySQL
- MySQL query to get the last created table name (most recent)?
- Display only a specific duplicate record in MySQL
- How can we find the most recent and most oldest date from a table with the help of MySQL MAX() and MIN() functions?
- How do I select 5 random rows from the 20 most recent rows in MySQL?
- MySQL query to display record with maximum count values in a group with other column values?
- Display the record with non-duplicate Id using MySQL GROUP BY and HAVING
- Display all records ignoring the current date record in MySQL
- How to select most recent date out of a set of several possible timestamps in MySQL?
- How to Get the most recent file in a directory in Linux?
- Display duplicate record as a distinct value with corresponding values as distinct comma separated list in MySQL?
- Display distinctly ordered MongoDB record with skip and limit?
- How to find the most recent file in a directory on Linux?
- Implement specific record ordering with MySQL
- MongoDB query to select 10 most recent documents without changing order?

Advertisements