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

Calculate time

Status
Not open for further replies.

zrazzaq

MIS
Apr 13, 2005
102
US
Hi:
Now that I converted the time into hours minutes and seconds, I need to add them to different fields for example:
1:20:36 + 3:03:43
Now in Access it will not do this for some reason...
How can I do this with a formula within VB or query...
Thanks
Zishan
 
zrazzaq,
zrazzaq said:
Now in Access it will not do this for some reason...

Huh?

Are 1:20:36 & 3:03:43 dates or strings? I suspect that if you are having problems that they are strings. If so, to do math with them you will need to convert them to dates. A couple of ways:
[tt] CDate("1:20:36") + CDate("3:03:43") = 4:24:19 AM
#1:20:36# + #3:03:43# = 4:24:19 AM[/tt]

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Hey Thanks...The thing is I changed the table to read Date/Time format in Access. But now that I try to update the table with like 49:15 which is 49 minutes and 15 seconds, it keeps telling me type mismatch. Anyone have any ideas for this?
Thanks
Zishan
 
I try to update the table with like 49:15
And how you try that ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Well the field is AVGTALKTIME and the DataType is Date/Time.
It will not pick up 49:15 but I fixed that by adding "00:" in front of it. Now it does not like 4:90:58...I do not understand.
Thanks
Zishan
 
and what is supposed to be 4:90:58 ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ok how about this I think me converting the minutes to hours function is incorrect:
Code:
Public Function ConvTime(sSecc As String)

   Dim iPoss As Integer
    'iPos = InStr(n, ":")
    p = Len(sSecc)
    q = 3
    'Lets get seconds first
    strn = Right$(sSecc, q)
    
    'To get minutes
    n = Left$(sSecc, p - q)
    If n < 60 Then
        n = sSecc
        ConvTime = n
        ConvTime = "00:" & n
        
    Else
        n = FormatNumber(Div0(n, 60), 2)
        n = ReplaceCharacter(n, ".", ":")
        
        ConvTime = n & strn
    End If
End Function
I think this is where it is messing up.
It suppose to convert something like 69:23 which is 69 minutes and 23 seconds to Hours:minutes:seconds.
If there is an easier way to convert this please let me know
thanks
Zishan
 
I already gave you a solution in your previous thread with the TimeSerial and Eval functions:
Public Function ConvTime(sSecc As String) As Date
ConvTime = TimeSerial(0, 0, Eval(Replace(sSecc, ":", "*60+")))
End Function


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Nice it works thank you so much for your help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top