[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

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 ?
0
JOHNHO
Asked:
JOHNHO
1 Solution
 
RuslanMCommented:
Try this :

Private Sub Command1_Click()
Dim t1 as Date, t2 as Date, t3 as Date
t1=text1.text
t2=text2.text
if t1>t2 then
    t3=t1-t2
else
    t3=t2-t1
end if
text3.text=t3

Hope it works

0
 
crazymanCommented:
you should use datdiff for comparing dates.
text3=datediff("s",time1,time2)
gives differance in seconds
0
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mcriderCommented:
By the way, if you use my solution, please reject the current answer...

Cheers!
0
 
JOHNHOAuthor Commented:
thanks for trying to help me rustan m and crazy man.

nut mcrider code is more details.

thanks.

by the way mcrider, how do i send the point to you ?
0
 
JOHNHOAuthor Commented:
thanks for trying to help me rustan m and crazy man.

nut mcrider code is more details.

thanks.

by the way mcrider, how do i send the point to you ?
0
 
mcriderCommented:
Posting for the points...

Just accept this answer.

Cheers!
0
 
mcriderCommented:
Thanks for the points!

Cheers!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now