Start a new topic

Adding Months

Hi, I'm new to these forums but have been using IOM for a while and have hit a headscratcher, I could really use some help if anyone has a good workaround:

I'm setting up a new Recurring Gift Import and the installment start date needs to be calculated. If the Gift Date is before the 17th of the month, the first installment is taken on the 5th of the following month, if the Gift Date is on or after the 17th, the start date will be the 5th in two month's time. i.e. a gift taken on 14/10/2014 will start on 05/11/2014 and a gift taken 19/10/2014 will start 05/12/2014. 

Its just a simple 'month + 1' or 'month + 2' situation but for some reason in the API it doesn't stop at 12 months. On testing with a date of 01/12/2014 the DateAdd 1 month function returns 01/13/2014 rather than 01/01/2015. Here's the code:

Dim GFDate As Date

Dim DDDate As String

GFDate = CDate(import.fields.getbyexcelname("B").Value)

If Day(GFDate) >= 17 Then

   GFDate = DateAdd("m", 2, GFDate)

   DDDate = CStr(GFDate)

   DDDate = "05" & Right(DDDate, 8)

ElseIf Day(GFDate)

   GFDate = DateAdd("m", 1, GFDate)

   DDDate = CStr(GFDate)

   DDDate = "05" & Right(DDDate, 8)

End If

Import.Fields.GetByExcelName("O").Value = DDDate

It looks like it is using US date format instead of UK format

mm/dd/yyyy vs. dd/mm/yyyy

You should look into the formatting and internationalization functionality of dates in VB just to make sure everything is in the UK format.

Thanks for the help, the regional settings were all ok, managed to fix it with that link though. 

I was using the VBA syntax for DateAdd, the 'm' specifier is for minute not month, it just needed this change:

GFDate = DateAdd("MM", 2, GFDate)

Login or Signup to post a comment