Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Code for calculating Time difference (http://www.go4expert.com/forums/code-calculating-time-difference-t21070/)

viv345 22Feb2010 16:12

Code for calculating Time difference
 
1 Attachment(s)
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.

virxen 22Feb2010 16:56

Re: Code for calculating Time difference
 
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 22Feb2010 17:35

Re: Code for calculating Time difference
 
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

viv345 22Feb2010 17:36

Re: Code for calculating Time difference
 
please correct it if their is any mistake

virxen 22Feb2010 18:43

Re: Code for calculating Time difference
 
1 Attachment(s)
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.

viv345 23Feb2010 18:26

Re: Code for calculating Time difference
 
Thanks for your help.


All times are GMT +5.5. The time now is 18:49.