Example:
seconds ="1015557";
Result should be:
11days 18h:05m:57s
How can do this in MySQL?
Example:
seconds ="1015557";
Result should be:
11days 18h:05m:57s
How can do this in MySQL?
                        
                            
                        
                        
                            On
                            
                            
                                                    
                    
                You can use a query like this:
SELECT
  DATE_FORMAT(date('1970-12-31 23:59:59')
   + interval 1015557 second,'%j days %Hh:%im:%ss') as result;
sample
mysql>     SELECT
    ->       DATE_FORMAT(date('1970-12-31 23:59:59')
    ->        + interval 1015557 second,'%j days %Hh:%im:%ss') as result;
+----------------------+
| result               |
+----------------------+
| 011 days 18h:05m:57s |
+----------------------+
1 row in set (0,00 sec)
mysql>
                        
                        
                            
                        
                        
                            On
                            
                            
                                                    
                    
                You can try this out:
SET @seconds = 1015557;
SELECT CONCAT(
            FLOOR(TIME_FORMAT(SEC_TO_TIME(@seconds), '%H') / 24), 'days ',
            MOD(TIME_FORMAT(SEC_TO_TIME(@seconds), '%H'), 24), 'h:',
            TIME_FORMAT(SEC_TO_TIME(@seconds), '%im:%ss')
        )
AS Result
Result should be:
11days 18h:05m:57s
Hopefully this helps!.
                        
                            
                        
                        
                            On
                            
                            
                                                    
                    
                If one is interested in fraction of seconds, the following combines the responses from Kent Aguilar and Steven Yang.
SELECT CONCAT(
  FLOOR(TIME_FORMAT(SEC_TO_TIME(@seconds), '%H') / 24), 'days ',
  MOD(TIME_FORMAT(SEC_TO_TIME(@seconds), '%H'), 24), 'h:',
  FLOOR(MOD(@seconds,3600)/60), 'm:',
  MOD(@seconds,60), 's'
) AS Result
                        
produces: