Mysql SEC_TO_TIME without end seconds - solution found

I have a Mysql table that stores dates in the format (YYYY-MM-DD HH: MM: SS).

What I want is the SUM part of HH: MM: SS for the selected rows, as I found in another post, I use the query

SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(date))) FROM table 

This request works. It summarizes the part I want and returns it in the format HH: MM: SS.

My question is whether it is possible to cut out seconds from the result.

I need to do this in the request, since the CMS I use does not allow me to use php for this part.

By the way, it would be great if I could return the result in days, hours and minutes, if the amount is more than 24 hours.

Thanks in advance

For everyone who is interested, I found a solution

 SELECT TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(hours))),'%H:%i' ) FROM table 
+6
source share
3 answers

Try this query, it will calculate days, hours and minutes -

 SELECT SUM(TIME_TO_SEC(date) DIV 86400) days, SUM(EXTRACT(HOUR FROM (SEC_TO_TIME(TIME_TO_SEC(date) % 86400)))) hours, SUM(EXTRACT(MINUTE FROM (SEC_TO_TIME(TIME_TO_SEC(date) % 86400)))) minutes FROM table 

Then use the CONCAT function to format these results on a single line.

+1
source

An effective solution is to cut out the last 3 characters:

 SELECT SUBSTRING(SEC_TO_TIME(seconds), 1, 5); 
+2
source
 SELECT SUBSTR(SEC_TO_TIME(1001),2,7); 

displays

 0:16:41 
-1
source

Source: https://habr.com/ru/post/911732/


All Articles