
- 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
Select date from MySQL and format to text?
To select date and format, use SELECT DATE_FORMAT(). Following is the syntax −
Syntax
select date_format(yourColumnName, '%e %b %y') from yourTableName;
Let us first create a table −
mysql> create table DemoTable -> ( -> DueDate date -> ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-12-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-15'); Query OK, 1 row affected (0.07 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-01-11 | | 2019-12-21 | | 2019-09-15 | +------------+ 3 rows in set (0.00 sec)
Following is the query to select a date from MySQL and format to text −
mysql> select date_format(DueDate, '%e %b %y') from DemoTable;
This will produce the following output −
+----------------------------------+ | date_format(DueDate, '%e %b %y') | +----------------------------------+ | 11 Jan 19 | | 21 Dec 19 | | 15 Sep 19 | +----------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL date format DD/MM/YYYY select query?
- How to select a specific record from MySQL if date is in VARCHAR format?
- Best way to change the date format in MySQL SELECT?
- Format date in MySQL SELECT * query uisng FORMATDATE() method?
- MySQL extract year from date format?
- MySQL query to select date from timestamp?
- Extract Numeric Date Value from Date Format in MySQL?
- Get date format DD/MM/YYYY with MySQL Select Query?
- MySQL query to select date from 00:00 to today’s date
- MySQL query to select closest date from today?
- How to select date from timestamp in MySQL?
- Convert MySQL Unix-Timestamp format to date format?
- How to select only MySQL date from datetime column?
- How to convert Python date format to 10-digit date format for mysql?
- Format date in MySQL to return MonthName and Year?

Advertisements