Code for calculating Time difference

Contributor
22Feb2010,16:12   #1
viv345's Avatar
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)
Pro contributor
22Feb2010,16:56   #2
virxen's Avatar
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
Contributor
22Feb2010,17:35   #3
viv345's Avatar
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
Contributor
22Feb2010,17:36   #4
viv345's Avatar
please correct it if their is any mistake
Pro contributor
22Feb2010,18:43   #5
virxen's Avatar
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
Contributor
23Feb2010,18:26   #6
viv345's Avatar
Thanks for your help.