Using AddMonths with a variable

I current am looking back 3 months from my current date, however that 3 months may change and I want to set the month value to a variable

Current
strCurrentStart.AddMonths(-3)

Tested
strCurrentStart.AddMonths(-strMonthPeriod)

This does not work. Can someone point me in the right direction.

Thanks

Hi @MattRPA2019,

Convert strMonthPeriod to integer or change it’s datatype to integer

Hi @MattRPA2019

Looks like you may be trying to add months to a string variable (strCurrentStart). It must be used with a DateTime variable type.

If you’ll provide your xaml file, we’ll take a look.

Cheers.

Troy

@MattRPA2019,

You can use add months for datetime variable types only.

 dateTimeDate.AddMonths(intMonths)

Here dateTimeDate is my date variable.
intMonths is my integer type variable to add months, if you want pass negative vale the add minus symbol to the intMonths.

1 Like

Thanks, that did the trick.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.