My Assistant
![]() ![]() |
|
|
Apr 4 2008, 12:47 AM
Post
#1
|
|
|
UtterAccess Editor Posts: 14,617 From: Northern Virginia, USA |
Below is a simple function that I put together as a result as result of information I have gathered through a variety of readings. I have added some of my own flare, but with a procedure this small, Its bound to be found else where in almost identical form ... so with that ...
This function will return the span of time between two times with the assumption that the total span is with in 24hrs. CODE Public Function TimeDiff(strInterval As String, _ dtStartTime As Date, _ dtStopTime As Date) As Long TimeDiff = DateDiff(strInterval, #12:00:00 AM#, _ Format(TimeValue(dtStartTime) - 1 - TimeValue(dtStopTime), _ "hh:nn:ss")) End Function strInterval can be any span identifier used in DateDiff() function, but is only makes sense to use "h","n", or "s". dtStartTime is a date/time that indicates the start time of the span. dtStopTime is a date/time that indicates the stop time of the span. ... Important note, the start time is ALWAYS assumed to be LESS than the stop time, so you will not get a negative value returned from this function ... Examples from the immediate window (us format on dates ... but this code *should* work with different regional settings for dates as well): ? TimeDiff("n", #4/3/2008 11:55 PM#, #4/4/2008 12:05 AM#) 10 ? TimeDiff("n", #1/1/1900 11:55 PM#, #4/4/2120 12:05 AM#) 10 Now ... lets reverse the start and stop dates .... ? TimeDiff("n", #4/4/2008 12:05 AM#, #4/3/2008 11:55 PM#) 1430 ... So ... as evidenced by the results, the start time is assumed to be less than the stop time, regardless of the date value tagged to the time ... Enjoy! ... {Please comment via PM if issues arise with this code} |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 4th February 2012 - 10:16 PM |