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

shieldscoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
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.
0
Martin LissOlder than dirtCommented:
Oh, and by using "s" you are looking for number of seconds, and depending on the date difference that could be a  number larger the 32,767 which is the Integer limit. Try changing intSeconds to a Long.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shieldscoAuthor Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ste5anSenior DeveloperCommented:
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.
0
shieldscoAuthor Commented:
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

0
Fabrice LambertFabrice LambertCommented:
Hi,

Instead of computing with weird formulas, why don't you perform a simple substraction between your start and end time ?
Then, you'll just need the datediff function to compute the hours difference.
Dim timeStart as Date
timeStart = DateSerial(Year(Now), Month(Now), Day(Now) - 2) + TimeSerial(16, 15, 4)

Dim timeEnd As Date
timeEnd = DateSerial(Year(Now), Month(Now), Day(Now)) + TimeSerial(17, 16, 14)

Dim timeDiff As Date
timeDiff = timeEnd - TimeStart

Dim militaryTime As String
militaryTime = DateDiff("h", timeStart, timeEnd) & " hours and " & Minute(timeDiff) & " minutes and " & Second(timeDiff) & " seconds."

Open in new window

In this snipet, result is as follow:
49 hours and 1 minutes and 10 seconds.

Of course it will be better, when building the resulting string to test if hours / minutes / seconds are equal or below 1, so you can adjust plurial.
0
shieldscoAuthor Commented:
I figured it out... Thanks used Clng
0
Martin LissOlder than dirtCommented:
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
0
shieldscoAuthor Commented:
Thanks Martin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.