DateAdd function - Arithmetic operation resulted in an overflow

borris83

Member
Joined
Apr 30, 2009
Messages
23
Programming Experience
Beginner
Hi everyone,

I am using the following code to add some value to a date:

VB.NET:
Dim strdate As Date
        Dim numinterval As Double
        numinterval = 149548.720386359
        strdate = DateAdd(DateInterval.day, numinterval, #1/1/1601#)
        MsgBox(strdate)
The value numinterval is the number of days passed since 1/1/1601 (this is how date is counted for things like 'last logon time', 'last bad password' in Active directory)

I do some calculation and get that numinterval value in days..

But since I want it to return the time more accurately, I tried first multiplying numinterval by 1400 for number of minutes.. And I changed the interval as dateinterval.minute...

That worked fine!

But, when I tried again by multiplying it further by 60, to get the time accurately in seconds and changed the interval to dateinterval.second it throws the following exception:

Arithmetic operation resulted in an overflow

I changed the type of numinterval into long, but the same problem..

Can anyone suggest what I should do?
 
Last edited:
You should use the Date data type instead:
VB.NET:
Dim d As Date = New Date(1601, 1, 1).AddDays(149548.720386359)
As you see in that help page the Framework type is DateTime, you can click the link to find help for all the members Date type provides.
 
Back
Top