Solved

Ireport default Value expression question

Posted on 2013-06-27
8
1,931 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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
 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
Why does the Android Studio logcat show this error when the user presses the button? 2 46
couple of eclipse 5 36
What's wrong with this code? 4 22
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 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