Convert a string containing hours, minutes, seconds to decimal hours

后端 未结 2 1410
臣服心动
臣服心动 2020-12-20 09:47

I have an automatically generated Excel sheet that has a column containing string values representing time spans. The values have the following format:

17 ho         


        
2条回答
  •  攒了一身酷
    2020-12-20 10:10

    There may be better ways, but this is one way of doing it.

    hours = Trim(Split(timeString, "hours,")(0))
    minutes = Trim(Split(Split(timeString, "hours,")(1), " minutes,")(0))
    seconds = Trim(Split(Split(Split(timeString,"hours,")(1)," minutes,")(1), "seconds")(0))
    
    TimeInPercentage = CInt(hours) + (1/60) * (CInt(minutes)) + (1/3600) * CInt(seconds)
    

提交回复
热议问题