
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get maximum date from a list of varchar dates in MySQL
Let us first create a table −
mysql> create table DemoTable ( AdmissionDate varchar(100) ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Sunday, 11 August 2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Friday, 18 October 2019'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Thursday, 18 July 2019'); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable ;
This will produce the following output −
+-------------------------+ | AdmissionDate | +-------------------------+ | Sunday, 11 August 2019 | | Friday, 18 October 2019 | | Thursday, 18 July 2019 | +-------------------------+ 3 rows in set (0.00 sec)
Following is the query to get the maximum date from a list of varchar dates inserted above −
mysql> select max(str_to_date(AdmissionDate,'%W, %d %M %Y')) AS MaxDate from DemoTable;
This will produce the following output −
+------------+ | MaxDate | +------------+ | 2019-10-18 | +------------+ 1 row in set (0.04 sec)
- Related Articles
- MySQL query to get the current date from the list of dates
- MySQL query to retrieve current date from a list of dates
- Comparison of varchar date records from the current date in MySQL
- Find maximum value from a VARCHAR column in MySQL
- Getting the maximum value from a varchar field in MySQL
- Find date record after a particular date from a column with VARCHAR type in MySQL
- Searching BETWEEN dates stored as varchar in MySQL?
- Convert varchar to date in MySQL?
- Display distinct dates in MySQL from a column with date records
- Get the minimum and maximum value from a VARCHAR column and display the result in separate MySQL columns?
- How to find a particular varchar id in MySQL from a list of values?
- Filter dates from a table with DATE and NULL records in MySQL
- Convert VARCHAR Date to a different format in MySQL?
- How to select a specific record from MySQL if date is in VARCHAR format?
- Select dates between current date and 3 months from the current date in MySQL?

Advertisements