- 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
Order dates in MySQL with the format “01 August 2019”?
To display dates like “01 August 2019”, use ORDER BY STR_TO_DATE(). Let us first create a −
mysql> create table DemoTable1435 -> ( -> DueDate varchar(60) -> ); Query OK, 0 rows affected (1.08 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1435 values('01 August 2019'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1435 values('01 Feb 2018'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1435 values('31 Jan 2017'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1435 values('01 March 2019'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select −
mysql> select * from DemoTable1435;
This will produce the following output −
+----------------+ | DueDate | +----------------+ | 01 August 2019 | | 01 Feb 2018 | | 31 Jan 2017 | | 01 March 2019 | +----------------+ 4 rows in set (0.00 sec)
Following is the query to order dates in MySQL with the format “01 August 2019” −
mysql> select * from DemoTable1435 -> order by str_to_date(DueDate,'%d %M %Y');
This will produce the following output −
+----------------+ | DueDate | +----------------+ | 31 Jan 2017 | | 01 Feb 2018 | | 01 March 2019 | | 01 August 2019 | +----------------+ 4 rows in set (0.04 sec)
- Related Articles
- Java Program to format date as Apr 14 2019 01:35 PM IST
- Format hour in kk (01-24) format in Java
- Update table and order dates in MySQL
- MySQL search results by month in format 2015-07-01 11:15:30?
- How to get string as date in MySQL with dates as dot format specifier?
- How to change format of dates in a table column with a MySQL query?
- How to insert mm/dd/yyyy format dates in MySQL?
- Display Seconds in ss format (01, 02) in Java
- Implement ORDER BY in MySQL to order records in human readable format?
- MySQL ORDER BY Date field not in date format?
- Display hour in hh (01-12 in AM/PM) format in Java
- How to Order by date in MySQL but place empty dates in the end?
- Working with dates before 1970 in MySQL?
- MySQL query to order and display difference between dates from the current date
- Java Program to format date as Apr 19, 2019, 1:27 PM

Advertisements