exceltimecustom-formatting

Excel custom time format with optional hours


I have a range of data which are in a time format of hh:mm.ss (my original dataset is imported through a csv this way). I need to transform it to a correct format (hh:mm:ss) to make calculations and that's easily done using the replace functionality.

The issue is that some of these data don't have the hh part, they are just mm.ss, so when I replace "." with ":" they become hh:mm instead of mm:ss, e.g. 06m.30s becomes 06h:30m.

Does anyone know how to make a custom time format that will take as default value the mm and include the hh only when necessary?


Solution

  • This assumes that during the import process, the time column is imported as TEXT

    EDIT: Formula shortened.

    Convert the values to a REAL Excel time

    =TIMEVALUE(SUBSTITUTE(IF(ISERR(FIND(":",A2)),"00:"&A2,A2),".",":"))
    

    or

    =--(SUBSTITUTE(IF(ISERR(FIND(":",A2)),"00:"&A2,A2),".",":"))
    

    Apply your desired Time format to the result

    hh:mm:ss
    

    enter image description here