# calculate total hours and minutes between two times but .....

I use this code...
Timediff = Format(CDate(TimeNow) - CDate(TimeFirst), "Long Time")

but if i change windows clock to the next day, for example:

now = 25-nov-2004 11:07:15
first = 24-nov-2004 11:00:00

i want to get this timediff:

24:07:15

no ....
0:07:15

can you help me?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I use this function when calculating such things...

[code]
Public Function TimeDiff(LesserTime As String, LesserTimeDate As String, GreaterTime As String, GreaterTimeDate As String) As String
Dim Thrs As Single, Tmins As Single, Tsecs As Single, ReturnTime As String
Dim DTcheck As Single
Dim i, Var_tmp_Hour As Integer

DTcheck = DateDiff("d", LesserTimeDate, GreaterTimeDate)

Var_tmp_Hour = Hour(GreaterTime)
If DTcheck > 0 Then
For i = 1 To DTcheck
Var_tmp_Hour = Var_tmp_Hour + 24
Next

ElseIf DTcheck < 0 Then
TimeDiff = "ERROR"
Exit Function
End If
Thrs = Var_tmp_Hour - Hour(LesserTime)

If Thrs > 0 Then
Tmins = Minute(GreaterTime) - Minute(LesserTime)
If Tmins < 0 Then
Tmins = Tmins + 60
Thrs = Thrs - 1
End If
ElseIf Thrs = 0 And Minute(GreaterTime) > Minute(LesserTime) Then
Tmins = Minute(GreaterTime) - Minute(LesserTime)
Else
TimeDiff = "ERROR"
Exit Function
End If
Tsecs = Second(GreaterTime) - Second(LesserTime)
If Tsecs < 0 Then
Tsecs = Tsecs + 60
If Tmins > 0 Then Tmins = Tmins - 1 Else Tmins = 59
End If
TimeDiff = Thrs & ":" & Tmins & ":" & Tsecs
End Function
[/code]

To use it just call something like this:

[code]
MsgBox TimeDiff("11:00:00", "24/11/2004", "11:07:15", "25/11/2004")
[/code]
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Try using DateDiff ...

DateDiff("n",#24/11/2004 23.30#,#25/11/2004 23.35#)/60.0
0
Author Commented:
Thanks a lot!!!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.