Search code examples
vbscriptasp-classic

Adding multiple times together


I'm trying to add some data that is pulled from a database in the format of HH:MM:SS I'm trying to get them to add together so if we have 00:00:05 then 00:00:10 so we have 00:00:15

I have attempted both TimeSpan, DateTime but I get the following error:

Microsoft VBScript runtime error '800a01a8'

Object required: 'TimeSpan'

Script Location, line 157

This is the code:

    While Not objRS.EOF
  
  activecalls = activecalls + objRS("talkingagents")
  callswaiting = callswaiting + objRS("callswaiting")
  averagetalkingtime = averagetalkingtime + objRS("convavgtalkduration")
  totalqueue = totalqueue + 1
  totalcalls = totalcalls + objRS("totalcalls")
  newWait = objRS("convavgwaitduration")

  
  TimeSpan t1 = TimeSpan.Parse(newWait)
  TimeString FormattedDate = t1.Add(FormattedDate)
  
  timeString = timeString.Add(t1).ToString("dd\.hh\:mm\:ss")

Solution

  • Not clear with your code but this probably what you are looking for.

    t1 = CDate("00:00:05")
    t2 = CDate("00:00:10")
    t3 = t1 + t2
    MsgBox Right("00" & Hour(t3), 2) + ":" + Right("00" & Minute(t3), 2) + ":" + Right("00" & Second(t3), 2)