Showing times > 24 hrs

P

Paul Sutton

In excel there is a format type that will let you show
times > 24 hrs - for example 36:23 for 36 hrs, 23
minutes. How can this be emulated in Access.

I am taking the difference between 2 Date/Times, and want
to display the difference in hrs.

Thx
 
R

Rick Brandt

There is no such Time type in Access. You would need to write a custom function
that uses DateDiff() to get the difference in minutes and then do the math to
determine the hours/minutes and then return the result of that as a String.

SIMPLE EXAMPLE:

Function HoursMinutes(StartTime As Date, EndTime As Date) As String

Dim lngMinutes As Long

lngMinutes = DateDiff("n", StartTime, EndTime)
HoursMinutes = CStr(lngMinutes \ 60) & ":" & Format(lngMinutes Mod 60, "00")

End Function
 
H

Henro

Any suggestions as to how to use this?

Rick Brandt said:
There is no such Time type in Access. You would need to write a custom function
that uses DateDiff() to get the difference in minutes and then do the math to
determine the hours/minutes and then return the result of that as a String.

SIMPLE EXAMPLE:

Function HoursMinutes(StartTime As Date, EndTime As Date) As String

Dim lngMinutes As Long

lngMinutes = DateDiff("n", StartTime, EndTime)
HoursMinutes = CStr(lngMinutes \ 60) & ":" & Format(lngMinutes Mod 60, "00")

End Function
 
J

John Vinson

In excel there is a format type that will let you show
times > 24 hrs - for example 36:23 for 36 hrs, 23
minutes. How can this be emulated in Access.

It cannot, not with a Date/Time field.
I am taking the difference between 2 Date/Times, and want
to display the difference in hrs.

Calculate the difference in *minutes* (as a Long Integer) and use an
expression to display that duration as hours and minutes:

DateDiff("n", [start], [end]) \ 60 & Format(DateDiff("n", [start],
[end]) MOD 60, ":00")
 
R

Rick Brandt

The same way you use any other function. The OP indicated the need to display
the difference between two DateTimes in HH:NN format. Supplying two DateTimes
as arguments to the function below will do exactly that. In a query (for
example) you would add a calculated field...

TimeDifference: HoursMinutes(SomeDateField, SomeOtherDateField)
 
D

Douglas J. Steele

John Vinson said:
It cannot, not with a Date/Time field.

Not quite true, John. Since Access stores times as fractions of a day, when
you've exceeded 24 hours, Access adds a day to what it's storing. You can
convert it back if you really want to.

Function FormatTime(TimeToFormat As Date) As String

Dim intHours As Integer
Dim intMinutes As Integer

intHours = 24 * Int(TimeToFormat) + Hour(TimeToFormat)
intMinutes = Minute(TimeToFormat)

FormatTime = Format(intHours, "0") & ":" & _
Format(intMinutes, "00")

End Function

Of course, the alternative you proposed is a far better solution.
 
T

Tom Wickerath

You might also want to try "A More Complete DateDiff Function"
http://members.rogers.com/douglas.j.steele/Diff2Dates.html

Tom
___________________________________________


The same way you use any other function. The OP indicated the need to display
the difference between two DateTimes in HH:NN format. Supplying two DateTimes
as arguments to the function below will do exactly that. In a query (for
example) you would add a calculated field...

TimeDifference: HoursMinutes(SomeDateField, SomeOtherDateField)
 
L

lou lei

Paul Sutton said:
In excel there is a format type that will let you show
times > 24 hrs - for example 36:23 for 36 hrs, 23
minutes. How can this be emulated in Access.

I am taking the difference between 2 Date/Times, and want
to display the difference in hrs.

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Subtracting time...again 2
Time Calc 10
Need formula for calculating time 2
Calculation 1
Create Table style report 2
Tidal Times 9
Time and billing help 3
Addition Of "Short Time" 5

Top