can't calculate flying hour. how to add 50:20+1:23=

K

khaled831

i want to make a log book for my flying hours. i made a database. but can't
insert the flying hour in the record. like, i flew 5:30+3:40+.......total
hour comes like 990:00. plz tell me how to sum my hours. office only allows
me time like AM or PM. but i need hour not time.
 
P

PieterLinden via AccessMonster.com

khaled831 said:
i want to make a log book for my flying hours. i made a database. but can't
insert the flying hour in the record. like, i flew 5:30+3:40+.......total
hour comes like 990:00. plz tell me how to sum my hours. office only allows
me time like AM or PM. but i need hour not time.

If you record TimeOut and TImeIn, you can use a query to calculate the
elapsed time:

SELECT TimeCard.TimeIn, TimeCard.TimeOut, DateDiff("n",[TimeIn],[TimeOut])/60
AS Expr1
FROM TimeCard;


Then you can just sum the minutes and divide by 60 to get hours and fractions
thereof.

If you store the elapsed time, then you have to divide the result by 24
because the answer is in days. The integer part of the number represents
days, and the fractional part represents a part of a day, so multiply by 24.
 
E

Ed Robichaud

One solution is to log TO and LND times, then use the DateDiff function to
calculate elapsed time. Or, you can log elapsed time in hours and tenths
(i.e. 5:10= 5.2, 5:30=5.5, etc.) then use normal math functions to
add/subtract times.
 
D

Damon Heron

If you have a form with the record source set to your table of times, you
could add a textbox to display your total hours, and in the afterupdate of
the form:

Private Sub Form_AfterUpdate()
SumofHrs
End Sub

which calls the sub:

Sub SumofHrs()

Dim myArray(2) 'array to hold hours and minutes
Dim pos As Integer 'need position of ":" for hrs -could be 1 digit or 2
Dim hrs As Integer
Dim mins As Integer
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

On Error GoTo ErrorHandler

Set dbs = CurrentDb
strSQL = "SELECT tableofFlyingtime.YourTimeRecorded FROM
tableofFlyingtime"
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
'I called the table "tableofFlyingTime", timefield in the table
"YourTimeRecorded"
'If the recordset is empty, exit.
If rst.EOF Then Exit Sub

With rst
Do Until .EOF
pos = InStr(1, !YourTimeRecorded, ":", 1)
myArray(1) = CInt(Left(![YourTimeRecorded], pos - 1))
myArray(2) = CInt(Mid(![YourTimeRecorded], pos + 1, 2))
hrs = hrs + myArray(1)
mins = mins + myArray(2)
.MoveNext
Loop
End With
hrs = hrs + Int(mins / 60)
mins = mins Mod 60
Me.txtsum = hrs & "hrs and " & mins & "minutes." 'textbox to display
total
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub

ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub

HTH
Damon
 

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

Top