Jump to content
We've recently updated our Privacy Statement, available here ×

How to add months to java.util.date field.


acdacd

Recommended Posts

Is there a way to add 2 months to a date field in iReport?

I created a variable with this expression: new java.util.Date($F{mydatefield}.add(Calendar.MONTH,2))

Compile error is “The method add(int, int) is undefined for the type Date”.

The variable and {mydatefield} are both java.util.Date.

Any suggestions? Thanks in advance.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi!

 

Method "add" is the method of java.util.Calendar, but not java.util.Date

 

You need:

1. Write java-class to work with dates (or find in internet, it's named approximately "DateUtils").

Example method of whis class:

public static Date addField(Date date, int field, int count) {

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

calendar.add(field, count);

return calendar.getTime();

}

 

 

2. Define classPath in iReport(Tools/Options/Classpath) with path to DateUtils.class

 

3. in iReport define Initial Value Expression for Variable:

ru.rtec.sgsr.util.report.DateUtils.addField($F{mydatefield}, Calendar.MONTH, 2)

 

With best regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...