Question

SELECT DATE_FORMAT('%m-%e-%Y','2010-01-05');

Why is it that that returns NULL when I'd expect it to return 05-01-2010? The sql fiddle:

http://sqlfiddle.com/#!2/db6d96/1

Thanks!

Was it helpful?

Solution

You are doing it wrongly.

DATE_FORMAT(date,format)

First param is date and 2nd param is format as

SELECT 
DATE_FORMAT('2010-01-05','%m-%e-%Y');

AND if the input date is in the format Y-m-d ( which is mysql date format)

Then to convert it to d-m-Y it should be

SELECT 
DATE_FORMAT('2010-01-05','%d-%m-%Y');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top