?
Solved

Time Difference

Posted on 2003-03-24
12
Medium Priority
?
173 Views
Last Modified: 2010-07-27
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
Comment
Question by:bobubi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8196078
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
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8196096
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
 

Author Comment

by:bobubi
ID: 8196116
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8196170
bobubi  that will only return WHOLE hours, and will not correctly handle partial hour intervals....

0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8196177
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
 

Author Comment

by:bobubi
ID: 8196182
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
 

Author Comment

by:bobubi
ID: 8196191
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
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 60 total points
ID: 8196245
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
 
LVL 3

Expert Comment

by:DocM
ID: 8197361
DateDiff gives the minutes also.

result = DateDiff("n", #8:15:00 AM#, #9:00:00 PM#)
hr = result \ 60
mn = result Mod 60
0
 

Author Comment

by:bobubi
ID: 8209577
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
 

Expert Comment

by:CleanupPing
ID: 8531720
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
 

Expert Comment

by:rodrig
ID: 8898583
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question