[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-24
3
Medium Priority
?
1,121 Views
Last Modified: 2008-02-26
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?
0
Comment
Question by:jorgeani
3 Comments
 
LVL 2

Accepted Solution

by:
craigewens earned 200 total points
ID: 12663733
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
 
LVL 6

Expert Comment

by:mmusante
ID: 12663783
Try using DateDiff ...

DateDiff("n",#24/11/2004 23.30#,#25/11/2004 23.35#)/60.0
0
 

Author Comment

by:jorgeani
ID: 12664173
Thanks a lot!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question