Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Difference

Status
Not open for further replies.

ahhuang

Programmer
Apr 1, 2002
61
SG
I have 2 textboxes to input start time and end time in 24hr format. Eg : 01:00
My entry is : start date :01:45
End date:12:15
Result:10.5 hr
I am unable to find the difference of these 2 times.
Kindly advice,if possible it would be great if there is code provided.
Thanx :)

 
Try:

Code:
dim iHours as integer
dim iMinutes as integer
dim iNoMinutes as integer

iNoMinutes = Datediff("n",cdate(text1.text), cdate(text2.text))

iHours = int(iNoMinutes / 60)
iMinutes = inominutes mod 60

 
Hi

If you look up the Datediff function in Help it should point you in the right direction although here is a wee bit of code to get you going :

Code:
Private Sub Command1_Click()

Dim diff As Single
'The "n" gives you the difference in minutes and then divide by 60 to give you the hours. You could use "h" but this rounds up to the nearest whole hour
diff = (DateDiff("n", Text1.Text, Text2.Text)) / 60

'Just displays the result
MsgBox diff

End Sub

Hope this helps, Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top