Solved

Ireport default Value expression question

Posted on 2013-06-27
8
1,895 Views
Last Modified: 2013-07-09
Hi,

I'm new to Ireport and have been struggling to find a way to get a TODATE parameter with a class of java.sql.timestamp to default to 23:59:59.  The problem is that a Date value always defults to midnight, so if the user chooses a TODATE of today, none of the data from today would be displayed.

I know this can be corrected in the default value expression- but I can't locate the correct code to designate 23:59:59.  Can any one help?  Thanks!
0
Comment
Question by:jjg1576
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:earth man2
ID: 39287237
public void testTimestamp() {
  java.util.Date date = new java.util.Date(2013,6,29,23,59,59);
  java.sql.Timestamp stamp = new java.sql.Timestamp(date.getTime());
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 39290060
If you don't want to use a default value expression you can pass the parameter to a map. I'd suggest you create a date and then subtract one second from it (1000 milliseconds), so you always get the 23.59.59.
0
 

Author Comment

by:jjg1576
ID: 39290348
Thanks for your responses-

Actually, even if i knew how to use the default value expression with today's date + 1 day it would do the trick.  I'm just struggling with the code for adding 1 day.  In crystal you could use dateadd, but I don't know the equivalent in Ireport.  ANy thoughts on how to do this?

Thanks!
0
 
LVL 35

Expert Comment

by:girionis
ID: 39292414
How do you pass the date in your ireport template? You can create the date before-hand and pass it as a parameter in a map.

To add one day to a date you can do something like this

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 1);
Date d = cal.getTime();

Open in new window

0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:jjg1576
ID: 39294911
Currently i am just using a third parameter.  I have FromDate, Todate and Tdate.

in the report Query I use the following code

     and testresult."testdate" >= $P{From_Date}
     and testresult."testdate" <= $P{TDate}

The TDate parameter references ToDate in it's default value expression with the following code:

$P{To_Date} + 1

Since Todate defaults to today's date (same as FromDate), the default value in TDate allows for an extra day to be added if the client enters the same day in both FromDate and Todate filters (these are the filters that prompt the user when the report is run).

So in a roundabout way this gets the data needed, it just seems like there must be an easier way to do it without making 3 parameters.
0
 
LVL 35

Expert Comment

by:girionis
ID: 39299711
Well you need three parameters since you store three dates. But you could do it with only two parameters, if you add dynamically one day to the one parameter you want.
0
 

Accepted Solution

by:
jjg1576 earned 0 total points
ID: 39300757
Ok thanks-

but really I only want two dates, just didn't seem to be a way to do it without a third.  I have it working, which is the important thing.  Just seemed odd that I could do it with two in Crystal.  Guess I still have a lot to learn about Ireport.  Thanks again for your help.
0
 

Author Closing Comment

by:jjg1576
ID: 39309798
My solution did what i wanted it to do- I just wanted to see if there was an easier way to do it.  The other solutions offered weren't specific enough.  That may be my fault as I am a novice at ireport and probably still have problems grasping some of the explanations.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now