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

I have two tables that store time a

Status
Not open for further replies.

MTBChik

Technical User
Jun 19, 2001
58
US
I have two tables that store time as string in this format:
01:20:21.92 (ex.) with a bunch of spaces after the time.

Ultimately, I need to add the two times together, but when I trim the spaces and then set the properties of each field to Long Time in a query, it still concatenates the two times as if they were strings. Ex: 13:20:21 + 18:00:00 results in 13:20:2118:00:00

I've been looking at this waaaay to long and it is driving me crazy.

Any help greatly appreciated.
 
Hi,
Try the following code for the addition of two times. I am not sure if this is an efficient way but it works. To use this, you must first separate the hours, minutes and seconds parts of the two times. I have used actual numbers in my code but must substitute those numbers with the separated parts.

h = 18 + 13 ' Adding the hours part of the two times
m = 20 + 44 ' Addin the minutes part of the two times
s = 21 + 40 ' Addin the seconds part of the two times

If s >= 60 Then
m = m + Int(s / 60)
s = s Mod 60
End If

If m >= 60 Then
h = h + Int(m / 60)
m = m Mod 60
End If

h = h + nh

MsgBox h & ":" & m & ":" & s

Hope it helps. Let me know what happens.
With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top