• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Time Difference

Hi. Does anyone know any method to find the interval hours between two times?
For instance, 8:00AM - 9:00PM, how can I find the interval hours.

All answers are appreciated. Thanks
0
bobubi
Asked:
bobubi
1 Solution
 
Arthur_WoodCommented:
dim Diff as Single

Diff = (EndTime - StartTime) * 24

Times/Dates are REALLY stored, internally, in VB, as NUMBERS, of type SINGLE (with a Decimal point), where the Integer part of the value(to the left of the decimal point) is the NUMBER of days since 12/31/1899, and the Fractional part(to the right of the decimal point)
is the fraction of 1 day, as measured in seconds.

AW

0
 
Arthur_WoodCommented:
thus

Diff = (#9:00 PM# - #8:00 AM#) * 24

and this yields Diff = 13 (13 hours)

where

Dif = (#9:15 PM# - #8:00 AM#) * 24  ==> 13.25 (13 hours 15 minutes = 13.25 hours)

AW
0
 
bobubiAuthor Commented:
I have just found out another solution:
DateDiff("h", Time1, Time2) = 13
This works too.

Anyway, I have to thank you AW for your help!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Arthur_WoodCommented:
bobubi  that will only return WHOLE hours, and will not correctly handle partial hour intervals....

0
 
Arthur_WoodCommented:
try it with Time1 = #9:15 PM# and Time2 = #8:00 AM#  to see what I mean...that will also return 13, but correctly should be 13 hours 15 minutes....

AW
0
 
bobubiAuthor Commented:
I have just found out another solution:
DateDiff("h", Time1, Time2) = 13
This works too.

Anyway, I have to thank you AW for your help!
0
 
bobubiAuthor Commented:
oh yah, I got what you mean.
It will produce a more exact time than using the DateDiff.
But may I know what's the two hex signs for?
0
 
Arthur_WoodCommented:
the #....# cause VB to convert the STRING value between the #...#s to a Date value (as I described earlier).


If you have the values in a Date variable, then DON'T use the #, but if the values are in a textBox ( or as a string value), then USE the #s, or the cDate function....
0
 
DocMCommented:
DateDiff gives the minutes also.

result = DateDiff("n", #8:15:00 AM#, #9:00:00 PM#)
hr = result \ 60
mn = result Mod 60
0
 
bobubiAuthor Commented:
by the way, does anyone know how to disable the checkboxes in the listview. I tried 'Ghosted' but only the items are frozen. I am still able to tick the checkboxes. Any solutions?
0
 
CleanupPingCommented:
Hi bobubi,
This old question (QID 20561140) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
rodrigCommented:
I have seached for code like the above. It is great. I am however having prolems getting times from a list box to to be inserted into the code. The time in the list is written "9:00 AM "

result = DateDiff("n", Time1  ,#12:00 PM#)

This resuls in the following error:
Type mismatch: 'Time1'

Help here would be much appreciated

 
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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