tags:

views:

506

answers:

2

I am trying to divide a sum of integers by a sum of [h]:mm:ss to get [s]. I am doing this by what seems to me to be this wild contortion.

temp = Split(Format(Range("D" & rInx).Value, "hh:mm:ss"), ":", -1, vbTextCompare)
answerDelay = CInt(temp(0)) * 3600 + CInt(temp(1)) * 60 + CInt(temp(2))

Because this seems rather odd to me I thought I would put it out there for you brains to look at and tell me a better way of doing it.

This is the end of a formula on a worksheet in short would be

range(B1)=838
range(C1)=26:38:44
range(D1)=range(C1)/range(B1)

The answer for this is 109 seconds.

It does work as I have it here, I just am not satified with my solution.

Do you have a better solution?

Thanks way in advance! Craig

A: 

You can use a TimeSpan to convert the time to seconds and and devide it afterwards.

I havn't tested it but somthing like this in C#:

var seconds = new TimeSpan(26, 38, 44).Seconds;

Is that what you meant?

asgerhallas
No it isn't but I certainly appreciate your timely response, I am using VBA not C++
CABecker
VBA has a DateDiff function, but there is no equivalent of TimeSpan which exists in C#
Lunatik
Sorry I didn't notice it was VBA and Excel. I'll open my eyes now :)
asgerhallas
+3  A: 

Excel keeps times as fractions of a day, i.e. 24 hours = 1.0. To convert to seconds, simply multiply by 24*60*60.

Mark Ransom