1

2012-02-14?

How can I modify the above MYSQL statement to format the date into string date format i.e.

2012-FEB-02?

1
  • 02 in the original date was the month, yet you want FEB-02 (i.e. month appearing twice, in different forms) in your output? Commented May 29, 2012 at 13:46

3 Answers 3

4

Use MySQL's DATE_FORMAT() function:

SELECT DATE_FORMAT('2012-02-14', '%Y-%b-%d');
Sign up to request clarification or add additional context in comments.

Comments

1

Have a look at MySQLs DATE_FORMAT, it gives you alot of possibilities to format a given date to your needs.

Example:

SELECT DATE_FORMAT('2012-02-14', "%Y-%b-%m");

Result:

2012-Feb-02

... and if you really want the month abbreviation in capital letters (aka FEB instead of Feb, like your example result), simply wrap an UPPER around it:

SELECT UPPER(DATE_FORMAT('2012-02-14', "%Y-%b-%m"));

Result:

2012-FEB-02

Comments

0

MYSQL DateFormat function.

DATE_FORMAT(<your_date_field>, '%Y-%b-%d')

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.