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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff, but what about a Time Diff type of function? 2

Status
Not open for further replies.

Kinl

Programmer
Joined
Mar 19, 2001
Messages
168
Location
US
I'm trying to subtract the time between two times in the medium format.

Is there a function to do this?

I'll then be displaying the result in a disabled textbox. This result will be formatted in the short date format in that textbox.

Is there a function to do this? Or how can I do this?

Thanx
Donn
 
Datediff has intervals of hours, minutes and seconds. What is medium format?
David Paulson


 
Medium Format:

hh:mm ampm

Thanx!
Donn
 
The term "medium format" is usually used to describe a format applied to the date/time value when it is displayed. The internal value to which you apply this format is normally an Access date/time column, or a VBA variable of Date data type. These values have both a date and a time component. If you're only using them for time, the date component will be 0. I'm going to assume the start and end times are Date variables, though I think it will also work if they are time strings.

This code will set the value of your text box to the number of elapsed hours and minutes, displayed in a format like Medium Time:
Dim ElapsedMin As Long
Dim Hours As Long, Minutes as Long
ElapsedMin = DateDiff("m", StartTime, EndTime)
Hours = ElapsedMin \ 60
Minutes = ElapsedMin Mod 60
txtMyTextBox = CStr(Hours) & ":" & CStr(Minutes)
(Note: This assumes that StartTime and EndTime with a whole number of minutes each. The code given does not attempt to round the difference to the nearest minute.) Rick Sprague
 
Thank you!! I appreciate it. I was having a hard time explaining what I wanted to happen. But you decifered it quite well! Thank you.

Donn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top