jkeri Posted January 16, 2019 Share Posted January 16, 2019 IN my query I have a date field $F{DATE1} as class java.util.DateWhat I want to do is to print and concatenate $F{DATE1} and $F{DATE1} + 6 daysI want my result like this: 01/01/2019 | 01/07/2019 My expression is:new SimpleDateFormat("MM/dd/yyyy").format($F{DATE1})+"|"+new SimpleDateFormat("MM/dd/yyyy").format($F{DATE1} +6)What is the correct exression to accomplish this? Thank you in advance. Link to comment Share on other sites More sharing options...
Solution prusyn Posted January 18, 2019 Solution Share Posted January 18, 2019 Hi,I had to play around a bit, but was able to achieve your desired result. I have created parameter: <parameter name="cal" class="java.util.Calendar" isForPrompting="false"> <defaultValueExpression><![CDATA[Calendar.getInstance()]]></defaultValueExpression> </parameter>[/code]and variable:<variable name="newDate" class="java.util.Date"><variableExpression> <![CDATA[ ( $P{cal}.set($F{birthdate}.getYear()+1900, $F{birthdate}.getMonth(), $F{birthdate}.getDate()) || $P{cal}.add(Calendar.DATE, 6) ) ? null : $P{cal}.getTime() ]]></variableExpression></variable>[/code]Result looks like that: http://prntscr.com/m8xtdzI'll attach sample report with sample data. You should be able to run it without any issues. Let me know if this fits your requirements :) Link to comment Share on other sites More sharing options...
a.kuznt Posted January 18, 2019 Share Posted January 18, 2019 Hi,You can to use just java 8. Your expression is:new SimpleDateFormat("MM/dd/yyyy").format($F{DATE1})+"|"+new java.sql.Date($F{DATE1}.getTime()).toLocalDate().plusDays(6).format(java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy")) Link to comment Share on other sites More sharing options...
a.kuznt Posted January 18, 2019 Share Posted January 18, 2019 Hi,You can to use just java 8. Your expression is:new SimpleDateFormat("MM/dd/yyyy").format($F{DATE1})+"|"+new java.sql.Date($F{DATE1}.getTime()).toLocalDate().plusDays(6).format(java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy")) Link to comment Share on other sites More sharing options...
jkeri Posted January 21, 2019 Author Share Posted January 21, 2019 Thank you everyone for your help. The response from A. KUZNT was colser to what I was looking for. 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