Discussion

How to add 13 months to present date ?

hi all,

I want to add 13 months to present date, can any one help me ?
we can add days to the date, but it is long for my req ( i want to calculate leep year + check 13th month + check no of days are 28,29,30,31.. so this is too big to do )
if any one know any method in java .. or any function .. i can place it directly .

I am using V5.1

thank you,
vishnu v.r.s

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

August 17, 2009 - 10:16am

Hi, Use Calendar Class to add months.

import java.util.*;
public class AddMonths {
public static void main(String[] jags)
{
// Date d=new Date(2009,08,17);
Calendar c=Calendar.getInstance();
c.set(2009,1, 17);
c.add(Calendar.MONTH, 13); // Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules. For example, to add 13 months to the current time of the calendar,
//System.out.println(c.getTime());
}
}

I hope this makes sense to some extent.

August 17, 2009 - 11:22am

I found one function to add months but i am not able to use it properly .. it is throwing instance not found error ..

Info
@lib: ReportContentBuilder
function: addDaysByCategory
ruleset: Pega-WB

any one used this function please help me by providing code
thanks
vishnu V.R.S

October 30, 2012 - 6:17am

Hi Raazsekhar,

     I made use of the same function you mentioned ie., add() but it is not working as expected. It works well sometimes but not always.

For Ex: For todays add, if I add 3months, it gives me expected result as : 30 Jan 2013

            But if I add 2months, then i am getting an error as below:

                     A processing error has occurred.

                        Error Message: String was not a datetime "20130030T101504"

  I am really not understanding why is my date after adding 2months is taking as 2013/00/30. Month is the issue here...00 is not recognised as any month.

 Can you please help me out?

Thanks in advance.

November 7, 2012 - 11:33am

When using integers as Months, the Java Calendar class considers 0-11 as valid months. January is month 0, and December is month 11.

 

What happens in your case is that you pass in 10 for October, but the Java Calendar interprets it as November. If you add 3, you get February. The function returns 1, which you are interpretting as January. If you add 2, you are getting January, which returns 0, and you cannot interpret the zero.

 

Since the Pega date format uses integers 1-12 as months, you should subtract one from the pega month int when you pass it into the Java calendar functions, and add 1 to the month it that you get out of the Java calendar functions.

November 12, 2012 - 1:16am

Hi CWMCKENZ,

      Thank you so much for your reply. I have done the same you suggested and it worked fine.

Thanks

June 10, 2013 - 8:23am

hi..i need to add months to current date .Will the function: addDaysByCategory works for this and pleas e  let me know what parameters need to give exactly as its throwing me error when i tried with "@addDaysByCategory(@CurrentDateTime(), 4, "", USDefault)".Please suggest me on this.
 

September 11, 2013 - 4:30pm

Either write a java setp, or do some property set using existing functions as below (guess better than writing java code :) ) -

 

LOCAL.monthsInPast = 16

LOCAL.day = @(Pega-RULES:DateTime).day(@today())

LOCAL.month = @(Pega-RULES:DateTime).month(@today())+1

LOCAL.year = @(Pega-RULES:DateTime).year(@today())

PARAM.today = @(Pega-RULES:DateTime).date(LOCAL.year, LOCAL.month, LOCAL.day)

LOCAL.yearsToChange = LOCAL.monthsInPast/12

LOCAL.monthsInPast = LOCAL.monthsInPast - (LOCAL.monthsInPast/12)*12

LOCAL.year = LOCAL.year-LOCAL.yearsToChange

LOCAL.year = (LOCAL.month <= LOCAL.monthsInPast) ? LOCAL.year-1 : LOCAL.year

LOCAL.month = (LOCAL.month <= LOCAL.monthsInPast) ? (LOCAL.month-(LOCAL.monthsInPast-12)) : (LOCAL.month-LOCAL.monthsInPast)

PARAM.CalcDate = @date(LOCAL.year, LOCAL.month, LOCAL.day)

August 3, 2015 - 2:45pm

Hi team,

How to include Java Parameter in function? Please help

June 13, 2016 - 4:19am

you can use the following to add months to date:

@addToDate((@addMonthsToDate( @(Pega-RULES:DateTime).CurrentDateTime(), .MonthsNumber)), 0 , 0, 0, 0)