how do i calculate time ?

i has 3 text box


now the 1st text box show one time ie 12:00:59 am
and text 2 show 12:50:00 am

now i want my text 3  show the val after i minus the text1 and text2 val.

how do i put it in my command botton ?
JOHNHOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crazymanCommented:
text3.text = datediff("s",time1,time2)
will show the differance in seconds
0
JOHNHOAuthor Commented:
fail,

show me 0 value.


why ?

0
SiM99Commented:
Use this:

Text3.Text = DateDiff("s", Text1.Text, Text2.Text)

crazyman was right.....
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mcriderCommented:
Actually, try this code...

It will take the time in Text1 and Text2 and put elapsed time in text3.


Cheers!

The code:

Dim iLng As Long
Dim iHrs As Long
Dim iMin As Long
Dim iSec As Long
Dim lTime1 As String
Dim ltime2 As String
lTime1 = Format(CDate(Text1.Text), "hh:nn:ss")
ltime2 = Format(CDate(Text2.Text), "hh:nn:ss")
iLng = DateDiff("s", lTime1, ltime2)
iHrs = Fix(iLng / 3600)
iMin = Fix((iLng - (3600 * iHrs)) / 60)
iSec = Fix(iLng - (3600 * iHrs) - (iMin * 60))
Text3.Text = Format(iHrs, "00:") & Format(iMin, "00:") & Format(iSec, "00")
0
mcriderCommented:
By the way, if you use my solution, please reject the current answer...

Cheers!
0
SiM99Commented:
mcrider:
Format(CDate(Text2.Text), "hh:nn:ss") ??
you mean hh:mm:ss... ??


What you've done is the same as me/crazy, only you've sucked up more :)

putting in the hou/min/sec code was easy enough, but he didnt ask for that so i didnt
0
KDivadCommented:
nope, mcrider is correct. "m"'s are calculated as minutes ONLY when following "h"'s. The "correct" format chars for minutes are in fact "n"'s. If you try his code, you will find that it is indeed correct.
0
KDivadCommented:
Clear-up: Both will work in this case, but drop the "hh:" from yours and you will find it formatted in months and seconds.
0
SiM99Commented:
ok, yeah. you're right
that's for dates..

still, it sounded good :)
0
JOHNHOAuthor Commented:
thanks sim for trying to help me, but mcrider code is the better one.

cheers up try to answer the next question.

thanks for solving my problem
0
mcriderCommented:
JOHNHO,

I'm posting for the points... Glad I could help you...

SiM99,

I ALWAYS use "hh:nn:ss" when dealing with time formats because there used to be a bug in VB2 where giving the time format "hh:mm:ss" gave the month, not the minutes...  The format is in the documentation.  Both formats work in VB4, VB5, and VB6.

Cheers!


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcriderCommented:
JOHNHO,

You still there??
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.