DateRange type what is it how to use it?

0

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

jvway's picture
144
Joined: Mar 9 2009 - 11:43am
Last seen: 5 years 1 month ago

1 Answer:

4

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"

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.

sprilukin's picture
Joined: Jul 26 2011 - 7:08am
Last seen: 1 month 2 days ago

Interesting. Thanks for the info.

jvway - 8 years 4 months ago
Feedback