Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time calculations 1

Status
Not open for further replies.
Apr 10, 2000
155
0
0
US
This should be easy but I am new to this. I have two comboboxes on my form. Each is populated with time values that look like this:

6:00 AM
6:30 AM
etc

I want a person to be able to pick for example 10:00PM in one combobox and 5:00 PM in the other and have a text box show the number 5 which is the number of hours between the two boxes. If it were 7:30 PM and 12:00 AM it is obviously 4.5.

How can I do this?
 

Take a look at the DateDiff function.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 



Values in Textoxes are text, so they must be converted.

exs
Code:
    Dim x As String, y As String
    x = "6:00 AM"
    y = "6:30 AM"
    MsgBox Abs(TimeValue(x) - TimeValue(y)) * 24



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I did this and it works just like I need it to. Thanks.

TextBox4.Text = DateDiff(DateInterval.Minute, CDate(ComboBox1.Text), CDate(ComboBox2.Text)) / 60
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top