[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • 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
  • 4
  • 3
  • 2
  • +2
1 Solution
 
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
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:
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
 
mcriderCommented:
JOHNHO,

You still there??
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now