How to sort the date in php

Asked

Viewed 91 times

-1

Good afternoon, I need to sort the dates that come from the database, by day/month/year. EX: 16/07/2020 30/07/2020 01/08/2020

$sql_listar = "SELECT idprova as idprova, descricao as descricao ,disciplina as disciplina, DATE_FORMAT(dtprova,'%d/%m/%Y') as dtprova, idprof as idprof from prova order by dtprova";
  • failed to inform how the date is in the bank. DATETIME? DATE?

  • What should you do if someone answers your question? https://answall.com/help/someone-answers See how to accept at https://i.stack.Imgur.com/evLUR.png

  • @Leocaracciolo I’m wearing the DATE

2 answers

0

Exchange the alias of the dtprova column, for example, ALIASdtprova.

SELECT idprova as idprova, descricao as descricao, disciplina as disciplina, idprof as idprof, DATE_FORMAT(dtprova,'%d/%m/%Y') as ALIASdtprova from prova ORDER BY dtprova DESC;

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

To return with the date, (I changed the field data for the guy DATE)

inserir a descrição da imagem aqui

  • Didn’t work, removed the date

  • @Fernandomoreira, how so removed the date? You included it in select to be shown? dtprova as dtprova ?

  • It worked in SQL, but in PHP it didn’t work it removed the date

0

So friendly:

echo date('d-m-Y', strtotime($sql_listar));

Study date() for other parameters. And strtotime() also.

Browser other questions tagged

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