Mysql specific date format

Using MySQL

Table

ID Date 001 2010-05-01 002 2010-06-08 

Inquiry

 Select ID, Date from table; 

I want to show the date in a specific format

Expected Result

 ID Date 001 01-Mar-2010 002 08-June-2010 

How to make a query in mysql.

Query Request Help

+4
source share
3 answers

You can use DATE_FORMAT with the format string '% d-% M-% Y'.

 CREATE TABLE table1(ID varchar(100), Date datetime); INSERT INTO table1 VALUES ('001', '2010-05-01'), ('002', '2010-06-08'); SELECT ID, DATE_FORMAT(Date, '%d-%M-%Y') FROM table1; 

Result:

  ID Date
 001 01-May-2010
 002 08-June-2010
+6
source

Like this:

 SELECT ID, DATE_FORMAT(`Date`, '%d-%M-%Y') FROM table; 

You can find other date formatting options for MySQL here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

+1
source

use DATE_FORMAT() in mysql

view the link for all format options:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

0
source

All Articles