0

This is my mysql query to select time from seconds.

SELECT TIME_FORMAT(SEC_TO_TIME(120),'%H:%i' )

This will return as 00:02 (HOUR AND MINUTES)

I need to show time hour,minutes,seconds automatically if there is a hour and there is a minute. no need to show like 00:00:10.

Is there any mysql function for doing this?

App tester
  • 139
  • 1
  • 11

2 Answers2

1

Table ss:

id
50
70
3700

Query:

SQLFIDDLEExample

SELECT 
CASE WHEN id <60
      THEN TIME_FORMAT(SEC_TO_TIME(id),'%s' )
     WHEN id >= 60 AND id < 3600
      THEN TIME_FORMAT(SEC_TO_TIME(id),'%i:%s' )
     ELSE TIME_FORMAT(SEC_TO_TIME(id),'%H:%i:%s' ) END Time
 FROM ss

Result:

|     TIME |
------------
|       50 |
|    01:10 |
| 01:01:40 |
Justin
  • 9,634
  • 6
  • 35
  • 47
0

You can try this

SELECT sec_to_time(now())

This function automatically gives you time in H:M:S

Sharad
  • 3,562
  • 6
  • 37
  • 59