How can I get the DB date already formatted using the Max and Date_Format Joints

4

I'm trying to get the longest date entered in my BD , I'm trying to use the MAX and DATE_FORMAT functions together and the search result is not as expected, I have these dates registered:

2016-10-24
2016-10-25
2016-10-26
2016-10-27
2016-10-28
2016-10-31
2016-11-01
2016-11-03
2016-11-04
2016-11-07
2016-11-08

SELECT MAX(DATE_FORMAT(Data,'%d/%m/%Y')) as DataInicial FROM calendarioDolar
    
asked by anonymous 08.11.2016 / 18:01

1 answer

4

You must first find the date using MAX and only after that format, otherwise the database will understand that you should search using the alphabetical order. Correcting the position we would have:

SELECT DATE_FORMAT(MAX(Data),'%d/%m/%Y') as DataInicial
  FROM calendarioDolar
    
08.11.2016 / 18:10