How to convert date with date to date in select query?

0

Here is the photo below:

Follow the code:

select dt_abertura, count(1) as qtd
from tabela
group by dt_abertura;

How to convert date with time (2017-09-23 16:24:55) to date only (23-09-2017) ?

I would like to be able to group these values by date order example:

01-01-2017 then down 02 -01- 2017 e por ee goes

    
asked by anonymous 15.06.2018 / 17:03

3 answers

2

I managed to sort the way I wanted:

SELECT DATE_FORMAT(dt_abertura,"%d/%m/%Y") AS Data, count(1) as qtd
FROM tabela
group by DATE_FORMAT(dt_abertura,"%d/%m/%Y")
order by date(dt_abertura);

See the result:

Thanks to everyone who tried to help me.

    
15.06.2018 / 19:19
1

Try this:

select DATE_FORMAT(dt_abertura, '%Y/%m/%d'), count(1) as qtd
from tabela
group by DATE_FORMAT(dt_abertura, '%Y/%m/%d');

Docs : DATE_FORMAT .

    
15.06.2018 / 17:20
0

Tested with MySQL 5.7.12:

SELECT CAST(ROUND(CAST(CAST('2018-06-15 17:22:00' AS DATETIME) AS UNSIGNED) / 1000000) AS DATE);

In your case, it would be

SELECT CAST(ROUND(CAST(dt_abertura AS UNSIGNED) / 1000000) AS DATE) AS data, COUNT(*) AS qtd
FROM tabela
GROUP BY 1
ORDER BY 1 DESC;
    
15.06.2018 / 22:26