Jasper Reports - 在日期参数中添加一天 [英] Jasper Reports - Add one day to a Date Parameter

查看:127
本文介绍了Jasper Reports - 在日期参数中添加一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含以下参数的Jasper报告:

I'm creating a Jasper report that includes the following parameters:


  • DATESTART (日期)

  • 日期(日期)

  • DATESTART (Date)
  • DATEEND (Date)

这些参数表示日期范围对于包含时间的名为 DATECREATED (时间戳)的字段。我希望日期范围是INCLUSIVE,也就是说,如果我过滤2009年1月1日到2009年1月31日,那么2009年1月31日的任何DATECREATED值(例如2009年1月31日15:00) )将包含在报告中。

These parameters indicate a date range for a field called DATECREATED (Timestamp) which includes times. I would like the date range to be INCLUSIVE, that is, if I filter for "Jan 1, 2009" to "Jan 31, 2009", any DATECREATED value on Jan 31, 2009 (such as "Jan 31, 2009 15:00") will be included in the report.

当我过去使用Crystal Reports时,我使用DATEADD函数创建一个过滤器表达式,如下所示:

When I used Crystal Reports in the past, I used the DATEADD function to create a filter expression like the following:

{DATECREATED} >= {DATESTART} and {DATECREATED} < DATEADD("d", 1, {DATEEND})

(我意识到这不是语法上的是的,但你明白了。)

(I realize that this isn't syntactically correct, but you get the idea.)

有没有办法在Jasper Reports中做类似的事情?

Is there any way to do something similar in Jasper Reports?

推荐答案

如果您理解法语,那么在这个主题
(唯一不同的是它增加了一个月)

If you understand French, there the same question is asked in this thread (the only difference is that it is about adding a month)

建议的解决方案如下:

直接在SQL语句中执行查询(如果您的数据源当然是SQL数据源)。
使用MySQL你可以做类似的事情

Do it with SQL statement directly in the query (if your data source is a SQL datasource of course). With MySQL you can do something like

DATE_ADD($P{DATEEND},INTERVAL 1 DAY);

更多信息:日期和时间函数(MySQL doc)

另一个解决方案是使用Java可能的日期对象

The other solution is to use the Java possibly of the Date object:

我提出的建议如下:

$P{DATEEND}.setDay($P{DATEEND}.getDay()+1)

但我没有尝试过(这可能是错误的)。

But I did not try it (and it is probably wrong).

也许你需要定义一个新的日期变量DATEEND_1
,其值类似于:

Maybe you need to defined a new Date Variable DATEEND_1 with a value expression like :

new Date($P{DATEEND}.getTime() + 24*60*60*1000)

new java.util.Date($P{DATEEND}.getTime() + 24*60*60*1000)

并在查询中使用此新变量 V {DATEEND _1}

And use this new variable in your query V{DATEEND_1}.

(我再也不确定)

这篇关于Jasper Reports - 在日期参数中添加一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆