Jump to content
Changes to the Jaspersoft community edition download ×

DateRange type what is it how to use it?


jvway
Go to solution Solved by sprilukin,

Recommended Posts

Hi all,

In iReport 4.8 I was creating a new parameter and noticed the DateRange type in the drop down.  Googling doesn't showa definition for this and how to use it.  I do tons of date range filtering and this seems promising.  Can anyone point me to how to use this?

Thanks,

Jerry

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution

You can use DateRange type to define ranges like day-1, week, year, quarter  etc. and use this ranges as a query parameters.

For example lets say you have following parameter:

 

<parameter class="net.sf.jasperreports.types.date.DateRange" name="dateRange"><defaultvalueexpression><!--[CDATA[new net.sf.jasperreports.types.date.DateRangeBuilder("WEEK").toDateRange()]]--></defaultvalueexpression>
</parameter>

 
 
and following query:
 
<querystring>
<!--[CDATA[select * from test_table where $X{EQUAL, orderDate, dateRange}]]-->
</querystring>

when you will run such query you will get similar SQL:

select * from test_table where orderDate >= "START DAY OF CURRENT WEEK" and orderDate <= "END DAY OF CURRENT WEEK"[/code]

 

 

As an expression for DateRangeBuilder you can use following syntax:

"DAY+/-n"   - (for example "DAY+1", "DAY-23"  - no spaces and all uppercase) means n-th day after (or before) current day,

"WEEK+/-n", "QUARTER+/n", "SEMI+/-n", "YEAR+/-n"

 

This type is compatible with Date type thus if you will create filed of such type then you will be asked to fill it you can enter either relative date expression as described above or regular date.

 

Also you can read javadoc for DateRangeBuilder class in sources of JasperReports library to find all possible cases how to use it.

Hope this helps.

 

Thanks,

Sergey.

 

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