Link to home
Start Free TrialLog in
Avatar of shieldsco
shieldscoFlag for United States of America

asked on

Access Over Flow Error 6 on Time Difference

I'm getting an over flow error 6 on the line below:

 intSeconds = DateDiff("s", dtmSart, dtmEnd)


 dtmStart As Date, _
 dtmEnd As Date _
 ) As String
 Dim intHours As Integer
 Dim intMinutes As Integer
I'm getting a stack over flow error (6) on the line below:

 intSeconds = DateDiff("s", dtmSart, dtmEnd)


 Dim intSeconds As Integer
 
 Code:
 intSeconds = DateDiff("s", dtmSart, dtmEnd)
 intHours = intSeconds \ 3600
 intMinutes = intSeconds \ 60 Mod 60
 intSeconds = intSeconds Mod 60
 
 HoursMinutes = CStr(intHours) & " Hours and " & CStr(intMinutes) & " minutes and " & CStr(intSeconds) & " seconds."

Open in new window

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

It would help if you would post your unedited code since right now it looks like neither dtmSart nor dtmEnd has been assigned a value.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shieldsco

ASKER

When I change to long the result is the call end time in military time:

Call Start Time      Call End Time      Call Duration
4:15:04 PM              5:16:14 PM            17 Hours and 16 minutes and 14 seconds.
As already posted: Integer can only store values from -32767 to 32767. Thus are small numbers. Use always Long as long as your requirements don't restrict your data type.
As indicated above I changed to long see result above


 dtmStart As Date, _
 dtmEnd As Date _
 ) As String
 Dim intHours As Integer
 Dim intMinutes As Integer
 Dim intSeconds As Long
 
 
 intSeconds = DateDiff("s", dtmSart, dtmEnd)
 intHours = intSeconds \ 3600
 intMinutes = intSeconds \ 60 Mod 60
 intSeconds = intSeconds Mod 60
 
 HoursMinutes = CStr(intHours) & " Hours and " & CStr(intMinutes) & " minutes and " & CStr(intSeconds) & " seconds."

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I figured it out... Thanks used Clng
I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
Thanks Martin