Code for calculating Time difference

viv345's Avatar, Join Date: Feb 2010
Contributor
I am making a chart for calculating time difference in VB (Form with textboxes is attached for your perusal) how i write code for calculating time difference.
Attached Images
File Type: jpg Timedifference.jpg (8.0 KB, 6 views)
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
convert hours to minutes and add the minutes for both start and end
then subtract and convert back to hours.

for example
start 10:34 end 12:12
start-->10*60+34=694minutes end-->12*60+12=732minutes
timediff=end-start=732-694=38---->0 hours 38 minutes.

things to consider
================
1) time must be in 24hr format
2) end time must be after start time -->error message
or you assume it belongs to the next day. (start=23:50 end=00:10) (in this case you must add 24 hours to hours)
viv345 like this
0
viv345's Avatar, Join Date: Feb 2010
Contributor
Srry. I am new bee in coding but then also I have writing code like this:
Private Sub Text14_Click()
Text2.Text = "h"
Text3.Text = "n"
Text4.Text = "h"
Text5.Text = "n"
Text2.Text = 10 * 60 + 34 = 694
Text4.Text = 12 * 60 + 12 = 732
Text14.Text = timediff = Text4.Text - Text2.Text
End Sub
0
viv345's Avatar, Join Date: Feb 2010
Contributor
please correct it if their is any mistake
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
from the code you posted i assume you are talking about
visual basic 6.


i made you a simple project to see how it's done.

for questions post here.
Attached Files
File Type: zip project1.zip (1.3 KB, 23 views)
viv345 like this
0
viv345's Avatar, Join Date: Feb 2010
Contributor
Thanks for your help.