donbowden Posted April 11, 2009 Share Posted April 11, 2009 Hi everyone!I need to have a conditional statement that finds the number of days between two dates. If the second date is null, then it should calculate the the number of days between the first date and the current date, but if the second date is not null then return the actual number of days between the two dates. From what I can determine, I know I need to manipulate the data types but I have not been able to find the right syntax to make it work. ($F(DateType2) != null) ? New Date() - $F(DateType1) : $F(DateType2) - $F(DateType1)Much thanks for any help in resolving this issue.Don Code:($F(DateType2) != null) ? New Date() - $F(DateType1) : $F(DateType2) - $F(DateType1) Link to comment Share on other sites More sharing options...
donbowden Posted April 13, 2009 Author Share Posted April 13, 2009 Do I need to provides some additional information for warrant a response? I could sure use some help with this. Thanks. Link to comment Share on other sites More sharing options...
mdahlman Posted April 14, 2009 Share Posted April 14, 2009 Is your source for the report a database? If so, you'll find this calculation easier to perform in SQL. Regards,Matt Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted April 15, 2009 Share Posted April 15, 2009 Possible solution: new Integer( (int) ( ($F{DateType2}.getTime() - $F{DateType1}.getTime()) / (1000*60*60*24) )This calculate the date difference in millisecs and return the integer result.It does not consider partial days and so on.Another solution is to write a custom helper class to perform the calculation with more accuracy.Giulio Link to comment Share on other sites More sharing options...
donbowden Posted April 15, 2009 Author Share Posted April 15, 2009 Hi Giulio,Thank you for your response. I attempted your line of code and received the following error. First let's review the actual code used with the actual field names:new Integer( (int) ( ($F{MORTAPPLYDATE}.getTime() - $F{CONTRACTDATE}.getTime()) / (1000*60*60*24) )Next is the following error as reported in the "Report Problems Window":Errors compiling N:JasperSoft iReportReportsProspectMasterList9.jasper!Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@830ed5 net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, calculator_ProspectMasterList_1239763427882_470676: 284: unexpected token: } @ line 284, column 9. 1 error at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:92) at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:192) at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:219) at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:135) at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:538) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986) Compilation running time: 391! Thank you again for your asistance. BTW, I have purchased and read your book and it provided much assistance.Regards,Don Link to comment Share on other sites More sharing options...
donbowden Posted April 15, 2009 Author Share Posted April 15, 2009 Hi Giulio,Please disregard my previous post. With a little closer examination; I noticed that adding a closing parenthesis corrected the issue and is working perfectly. Thanks for your help.Regards,Don Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now