How do I multiply a time value by a whole number in VB6 using the DateDiff function

For example: If I multiply 1:30 by 10, then my output should be 10:30 hours.

For example: If I multiply 1:30 by 10, then my output should be 10:30 hours.

Do more with

EXPERT OFFICE^{®} is a registered trademark of EXPERTS EXCHANGE^{®}

Also, why would you use

a = "1:30"

Multiplier = 2

result = myFunc(a, Multiplier)

MsgBox result

End Sub

Function myFunc(ByVal L2 As Date, ByVal Multiplier As Long)

ha = Hour(L2)

M = ha * Multiplier & ":" & Minute(L2)

myFunc = M

End Function

```
Private Sub Form_Load()
Dim a As Date
Dim Multiplier As Long
Dim Result As Date
a = CDate("1:30")
Multiplier = 2
Result = Multiplier * a
MsgBox Result
End Sub
```

>>the output is 1:30 so its not working

If you have dimensioned the variables correctly, the output is "2:30"

and not "1:30" :

Option Explicit

Private Sub Form_Load()

Dim a As String, Multiplier As Integer, result As String

a = "1:30"

Multiplier = 2

result = myFunc(a, Multiplier)

MsgBox result

End Sub

Function myFunc(ByVal L2 As Date, ByVal Multiplier As Long)

Dim m As String, ha As Integer

ha = Hour(L2)

m = ha * Multiplier & ":" & Minute(L2)

myFunc = m

End Function

You can specify the format to display in the way that you want it:

```
Dim a As Date
Dim Multiplier As Long
Dim Result As Date
a = CDate("1:30")
Multiplier = 2
Result = Multiplier * a
MsgBox Format(Result, "hh:nn")
```

>>The final result needs to be in a Time format also.

Try this :

Enum ole2

outputAsHours = 1

outputAsDays = 2

outputAsDayTimeFormat = 3

End Enum

Option Explicit

Private Sub Form_Load()

Dim a As String, Multiplier As Integer, result As String

a = "1:31"

Multiplier = 20

result = myFunc(a, outputAsHours, Multiplier)

MsgBox result

result = myFunc(a, outputAsDays, Multiplier)

MsgBox result

result = myFunc(a, outputAsDayTimeFormat, Multiplier)

MsgBox result

End Sub

Function myFunc(ByVal L2 As Date, ByVal L3 As ole2, ByVal Multiplier As Long)

Dim ha As Integer, hb As Integer, hc As Single

ha = Hour(L2): hb = Minute(L2)

hc = (ha * 60) + hb 'how many minutes is it?

hc = hc * Multiplier 'multiply it

Select Case L3

Case 1

hc = Round(hc / 60, 2) 'convert minutes to hours

myFunc = hc & " hours"

Case 2

hc = Round(hc / 60 / 24, 3) 'convert minutes to days

myFunc = hc & " days"

Case 3

hc = (hc / 60 / 24) 'convert minutes to days

myFunc = Fix(hc) 'convert days to "common time format"

myFunc = myFunc & " days and "

myFunc = myFunc & Format(hc, "hh:nn")

myFunc = myFunc & " hh:min "

End Select

End Function

## Premium Content

You need an Expert Office subscription to comment.Start Free Trial