如何在ireport中过滤字符串日期(jasper报告) [英] how to filter String dates in a ireport (jasper reporting)
问题描述
我想过滤两个日期之间的值
我的数据库中的
它像2014年7月12日一样保存为字符串,当我试图将所选日期的值输入到iReport时但似乎日期格式存在问题,并且在报告中显示所有值而不仅仅是所选日期
这是我试图过滤日期的代码在iReport中:
SELECT sent_by,sent_date,recive_date FROM 评估 WHERE decision = ' 批准'
AND (recive_date BETWEEN $ P {sdte} AND $ P {edte} )
这就是我用参数传递2个日期的方式
String strtdte = datechosser(jDateChooser2);
String enddte = datechosser(jDateChooser1);
字符串 reportSource = D:\ \completePrintinReport.jrxml跨度>;
Map< String,Object> params = new HashMap< String,Object>();
params.put( sdte,strtdte);
params.put( edte,enddte);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
连接c =(连接)ConnectionSet1.getInstance()。getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,params,c);
JasperViewer.viewReport(jasperPrint,false);
c.close(); P
{sdte} AND
P
{edte})
这就是我用参数传递2个日期的方式
String strtdte = datechosser(jDateChooser2);
String enddte = datechosser(jDateChooser1);
字符串 reportSource = D:\ \completePrintinReport.jrxml跨度>;
Map< String,Object> params = new HashMap< String,Object>();
params.put( sdte,strtdte);
params.put( edte,enddte);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
连接c =(连接)ConnectionSet1.getInstance()。getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,params,c);
JasperViewer.viewReport(jasperPrint,false);
c.close();
您可以更改表格设计,使receive_date成为日期时间或日期。选择表格,然后右键单击以转到设计视图。在那里你可以改变数据类型。保存。
否则你可以通过使用以下查询来实现它
SELECT sent_by,sent_date,recive_date FROM 评估 WHERE decision = ' 批准'
AND (CAST(recive_date AS 日期) BETWEEN
I want to filter the values between two dates
in my data base it saves like 12 /July /2014 as a string, and when i tried to get the values from chosen dates to a iReport but it seems there is a problem with date format and in the report it shows all the values not just the chosen dates
This is the code i tried to filter the dates in iReport:
SELECT sent_by, sent_date, recive_date FROM evaluation WHERE decision='Approve'
AND (recive_date BETWEEN $P{sdte} AND $P{edte})
and this is how i passed the 2 dates with parameters
String strtdte = datechosser(jDateChooser2);
String enddte = datechosser(jDateChooser1);
String reportSource = "D:\\completePrintinReport.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
params.put("sdte", strtdte);
params.put("edte", enddte);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
Connection c = (Connection) ConnectionSet1.getInstance().getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, c);
JasperViewer.viewReport(jasperPrint, false);
c.close();
P{sdte} AND
P{edte})
and this is how i passed the 2 dates with parameters
String strtdte = datechosser(jDateChooser2); String enddte = datechosser(jDateChooser1); String reportSource = "D:\\completePrintinReport.jrxml"; Map<String, Object> params = new HashMap<String, Object>(); params.put("sdte", strtdte); params.put("edte", enddte); JasperReport jasperReport = JasperCompileManager.compileReport(reportSource); Connection c = (Connection) ConnectionSet1.getInstance().getConnection(); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, c); JasperViewer.viewReport(jasperPrint, false); c.close();
You can change your table design to have the receive_date as datetime or date. Select the table and then right-click to go to design view. There you can change the datatype. Save it.
Else you can achieve it by using the below query
SELECT sent_by, sent_date, recive_date FROM evaluation WHERE decision='Approve' AND (CAST(recive_date AS Date) BETWEEN
这篇关于如何在ireport中过滤字符串日期(jasper报告)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!