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!

Convert Strings to Time

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.
 
I'm not sure what kind of format you have there but if you need to add times together you must first convert them to date types, then you can format the result any way you like:

Dim str1 As String
Dim str2 As String

str1 = "13:02:34"
str2 = "17:34:30"

Dim strTotalTime As String

strTotalTime = CDate(str1) + CDate(str2)

Debug.Print Format(strTotalTime, "hh:mm:ss")

VBSlammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top