PDA

View Full Version : Formatting result of diffrence between two times



Movian
06-09-2009, 01:44 PM
Hi,
i have the following code

Dim myrs As DAO.Recordset
Set myrs = CurrentDb().OpenRecordset("RoomTrack")
Do Until myrs.EOF
myrs.Edit
myrs.Fields("ElapsedTime") = Now() - myrs.Fields("EntryTime")
myrs.Update
myrs.MoveNext
Loop
myrs.Close
Set myrs = Nothing
Me.RoomStatus.Requery

I am using this to show the amount of elapsed time since the entry time. However its deciding that as its a time field it must be an actual time (E.G. 3PM) rather than an amount of time ( 3 hour and 3 minutes).

How would i go about altering this to ensure that it displays this an amount of time?

OBP
06-10-2009, 07:01 AM
Movian, it might be better to have it as a text field and format the data to go in to it.
You could use Int(Now() - yourfield) as the Hours and (Now() - yourfield) - Int (Now() - yourfield)* 60 as the Minutes. You could then format it with
Int(Now() - yourfield) & " Hrs " & (Now() - yourfield) - Int (Now() - yourfield)* 60 & " Ms"

Or you could leave it as Date/Time and try a Special Format to display it on a Form.

Movian
06-10-2009, 02:16 PM
i tried creating a statement as you showed OBP

However no matter how many hours between the 2 the hours always =0

and the minutes is always a 0.111216851 or equivalent number...

I have to say dates and times are my least fav type to be working with...

myrs.Fields("Elapsed Time") = CStr(Int(Now() - myrs.Fields("Entry Time")) & "Hrs " & (Now() - myrs.Fields("Entry Time")) - Int(Now() - myrs.Fields("Entry Time")) * 60 & "Ms")

OBP
06-11-2009, 04:35 AM
Can you post a small database or Excel sheet with some values in for me to "play" with for you?

Movian
06-11-2009, 05:50 AM
we have decided for speed of development to just put the current time on the form and allow the user to work out the diffrence in time themselves.

I can allways work on this later to get it to work :)

So i won't mark this solved just yet but i will return to it soon