Search code examples
mysqlexcelms-officeexcel-2013

My MySQL results at Excel sheets doesn't work good


I have a Sheet with My SQL import data from hours numbers format (without date), but exceed 24:00:00 When I refresh and import data, Excel shows me this: 11:46:02 If I change the Hours Format to [h]:mm:ss Excel shows me this: 1001243:46:02 In the equation receipt, Excel shows me this: 20/03/2014 11:46:02

In this way, I think it imports data with today's date. Indeed I realize Excel should import the data with date of 01/01/1990 and then the sum kept correct. I think it's interpreting the exceeded hours after 23:59:59 as a date, but I just suppose.

I have another Sheet with the same database from MySQL and this numbers works correct, so I think the problem is at Excel 2013, but I can't find a solution in this.

The query is:

SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(TIME(FROM_UNIXTIME(ch.datafinal)),TIME(FROM‌​_UNIXTIME(ch.datainicial)))))) AS tempo, usu.nomecompleto FROM usuarios usu LEFT JOIN chat_historicocliente ch ON (usu.codusuario = ch.operador) WHERE EXTRACT(MONTH FROM FROM_UNIXTIME(ch.datainicial)) = 02 AND EXTRACT(YEAR FROM FROM_UNIXTIME(ch.datainicial)) = 2014 GROUP BY usu.nomecompleto 

All query with time in hour bigger than 24 hours have this trouble Thanks


Solution

  • Your "tempo" is the result of SEC_TO_TIME() which can be literal OR numerical based on your input.
    The doc says

    mysql> SELECT SEC_TO_TIME(2378);
            -> '00:39:38'
    mysql> SELECT SEC_TO_TIME(2378) + 0;
            -> 3938
    

    Your are most likely falling under the second category