4

Using MySQL

Table

ID Date

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

Query

Select ID, Date from table;

I want to display a date in a specific format

Expected Output

ID Date

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

How to make a query in mysql.

Need Query Help

1
  • I think you have misspelled "May" in your expected output. Commented Aug 5, 2010 at 8:00

3 Answers 3

6

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

use DATE_FORMAT() in mysql

look at the link for all format option:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.