Solved

Ireport default Value expression question

Posted on 2013-06-27
8
1,872 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

760 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

22 Experts available now in Live!

Get 1:1 Help Now