How can I get the BD date already formatted using the Max and Date_format functions together

Asked

Viewed 89 times

4

I’m trying to get the biggest date registered in my BD, I am trying to use the functions MAX and DATE_FORMAT together and the search result is not what 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

What the query returns to me is the day 2016-10-31 and should be 2016-11-08, I understand that I am not executing the query correctly, what I am doing at the moment is this:

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

1 answer

4


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

SELECT DATE_FORMAT(MAX(Data),'%d/%m/%Y') as DataInicial
  FROM calendarioDolar
  • Hello @Sorack, thank you so much for the tip, solved my problem.

  • Dispose! I will add a brief explanation. If you can approve as correct answer it will be of great value to those who research for the same problem

  • 1

    I’m waiting for the 4 min for approval, there’s a time limit between response and approval.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.