Jump to content
Changes to the Jaspersoft community edition download ×

Days functions


martinh

Recommended Posts

I need the following in my Jasper Report, want I really don't know how to do this

 

I have 2 parameters:

$P{year}

$P{month}

 

I need to know the number of days in this month

and the number of days this year

 

For example year=2008, month=3

I need to know that number of days this month = 31

and number of days this year = 31+29+31 = 91

 

I have found the getGreatestMaximum() method in the java.util.Calender, but I really have no idea how I can determine these values.

 

In Jasper I can only assign a variable and not making a script that finally returns the value I need.

 

How can I realize the above in Jasper Reports?

 

Thanks for your reply

 

Martin

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Just make a Helper Class (for example "MyUtil.class") that has this method inside:

 

Code:
   public static int getLastDayOfMonth(int month, int year) {
month= month- 1;
Calendar c = new GregorianCalendar(year, month, 1);
c.add(GregorianCalendar.DAY_OF_YEAR, 31);
while (c.get(Calendar.MONTH) != month) {
c.add(GregorianCalendar.DAY_OF_YEAR, -1);
}
return c.get(Calendar.DAY_OF_MONTH);
}

 

Then do this as TextFieldExpression:

 

Code:
[code]MyUtil.getLastDayOfMonth($P{month},$P{year})

 

to get the number of days in the month of the year.

 

the other method to add the number of years till that month is for your own challenge! :-)

 

hth

C-Box

Link to comment
Share on other sites

Thanks, ... but how do I create such a helper class

 

In the Jasper manual there isn't something mentioned as Helper classes

 

Also I don't know how to write Java (only some javascript)

 

But I'm forced to use Japser Reports, so I feel myself in the water and I don't know how to swim :dry:

Link to comment
Share on other sites

Uhhh bad precondition.....

 

a helper class (it's just my name for it) is just a normal java class that must be within your CLASSPATH.

(so a "java-file" (e.g. MyHelper.java)that must be compiled via javac to a so called "class-file" (e.g. MyHelper.class))

 

But if you don't know how to write a java class then you should start learning java before using JasperReports.

 

 

JasperReports is just a library for Java Applications... so in my opinion, it does not make sense starting with JasperReports without having basic knowlegde of Java.

(as many expressions within JasperReports are directly Java).

 

Just my two cents.

C-Box

Post edited by: CBox, at: 2008/03/14 21:32

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...