There's a bug with the DateAdd function that's been known for 12 years and never fixed, apparently:


There is a defect when using the DateAdd vbscript function to increment a date using the Month (m) parameter. This error happens under the following scenario.

In the simplest form take the example below.

Original Date = 1/31/2015

You use the following vbscript function to add 1 month to this date

DateAdd(m, 1, "1/31/2015")

This will result in the error "Numeric overflow -- ERR #2 Line X" because SBM is actually trying to add a month to "1/31/2015" so the result would be "2/31/2015" which there is no Feb. 31 so it throws an error.

With this example you will get this error anytime the resulting date from the DateAdd would not exist. Other examples would be "10/31/2015" add a month and it would be "11/31/2015" Nov only has 30 days so that would throw an error.

The workaround in the article has some bugs in it. I created a function based on it that seems to work:

Function ModifiedDateAdd(startDate, incMonths)

Dim orgDay, orgMonth, orgYear
Dim newDay, newMonth, newYear
Dim newDate

newDate= DateSerial(orgYear, orgMonth + incMonths, orgDay) ' Increase start date by x months.

' When you increase Jan-31 by one month, you get March 3 (because Feb does not have 31 days)

newDay=Day(newDate) ' Capture new start Day
newMonth=Month(newDate) ' Capture new start Month
newYear=Year(newDate) ' Capture new start Year

if newDay <> orgDay Then ' If the new day and original day do not match,
newDate = DateSerial(newYear,newMonth,0) 'Reset start date to the last day of the previous month. This changes March 3 to be Feb 28.
End If

'Call Ext.LogWarningMsg("This is the value for New Date " & newDate)

ModifiedDateAdd = newDate

End Function

BTW, to fix the UTC Offset problem, do it this way:

' --- Calculate time zone offset from UTC
UTCOffset = DateDiff("h", dateAdd("s", Ext.DateToDBLong(Now), "1970-01-01 00:00:00"), Now)

Then subtract the offset from the UTC date value:

nDateLastCalibrated =  Ext.DateToDBLong(DateAdd ("h", -UTCOffset, Ext.DBLongToDate(nDateLastCalibrated)))

I heard Micro Focus is planning on dropping support for the current AppScript language, but this should be easy to fix and roll into the next release.
Responses (1)
  • Accepted Answer

    Monday, June 12 2017, 06:09 PM - #Permalink
    AppScript is being replaced by a modernized scripting offering, yes, called ModScript. We'll keep AppScript in the product for a few more releases as we bring ModScript up to its expected level of capabilities. Because ModScript is the future of scripting in SBM, I do not expect that we will be putting development effort into AppScript - especially for a defect that has not been addressed for 12 years. I'd encourage you to try the same situation out with ModScript and, if the same issue does occur (which I hope it does not), we'd correct it in ModScript for a future version of SBM.
    The reply is currently minimized Show
Your Reply

Recent Tweets

Twitter response: "Invalid or expired token."