How to get only the time?

0

I'm trying to get the "zeros" as the image shows

I have the following part of the query:

"sec_to_time(SUM(horas_semana)*3600) as horas_semana"

Which I do not know what else I can do to only show the "48" hours only.

Any advice?

    
asked by Jason Leandro R 21.04.2017 в 18:14
source

4 answers

2

You must define the output format. Something like this:

SELECT TIME_FORMAT(sec_to_time(SUM(horas_semana)*3600) as horas_semana,'%H') FROM table
    
answered by 21.04.2017 в 18:27
1

Understanding "draw" how to remove (not show), then you want the result of the query to only show the number of hours without minutes and seconds.

As suggested in the responses of @federhico and @SoftMolina, you can use the function TIME_FORMAT indicating the mask for hours %H :

TIME_FORMAT(sec_to_time(SUM(horas_semana) * 3600), '%H') as horas_semana
    
answered by 21.04.2017 в 19:27
1

To get only the time, minutes and seconds would be:

SELECT TIME(NOW())

although you could also use the DATE_FORMAT () function:

SELECT DATE_FORMAT(NOW( ), "%H:%I:%S" )

SELECT TIME_FORMAT(sec_to_time(SUM(horas_semana)*3600) as horas_semana,'%H') FROM table
    
answered by 21.04.2017 в 19:03
0

Use the HOUR

  

Returns the time. The range of the return value is from 0 to 23 for the values of time of day. However, the range of values of TIME is actually much higher, so HOUR can return values greater than 23 .

Example:

mysql> select HOUR(sec_to_time(SUM(horas_semana)*3600)) as horas_semana;
+--------------+
| horas_semana |
+--------------+
|           48 |
+--------------+
1 row in set (0.00 sec)
    
answered by 21.04.2017 в 20:37