Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Set a specific Date Format in MySQL?
To set a pecific date format, you need to use DATE_FORMAT() in MySQL. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ArrivalDate date ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(ArrivalDate) values('2019-01-31');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable(ArrivalDate) values('2019-04-26');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable(ArrivalDate) values('2019-03-01');
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 −
+----+-------------+ | Id | ArrivalDate | +----+-------------+ | 1 | 2019-01-31 | | 2 | 2019-04-26 | | 3 | 2019-03-01 | +----+-------------+ 3 rows in set (0.00 sec)
Following is the query to set specific date format in MySQL −
mysql> select Id,DATE_FORMAT(ArrivalDate, '%d-%M-%Y') from DemoTable;
This will produce the following output −
+----+--------------------------------------+ | Id | DATE_FORMAT(ArrivalDate, '%d-%M-%Y') | +----+--------------------------------------+ | 1 | 31-January-2019 | | 2 | 26-April-2019 | | 3 | 01-March-2019 | +----+--------------------------------------+ 3 rows in set (0.06 sec)
Advertisements
