acdacd Posted September 15, 2011 Share Posted September 15, 2011 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 More sharing options...
sanbez Posted September 16, 2011 Share Posted September 16, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now