cg8 Posted July 24, 2012 Share Posted July 24, 2012 Date pattern is set to "MM/dd/yyyy" in the text field properties. Dates are appearing like the following-- "7/3/112" instead of "7/3/2012".Let me know if any more information needed.Thanks in advance for your help! Text Field PropertiesExpression Class: java.lang.StringPattern: MM/dd/yyyyText Field Expression Below . . . Code:"Agreement will commence on <b>"+ $F{EXPECTEDSTARTDATE}.getMonth()+ "/" + $F{EXPECTEDSTARTDATE}.getDay()+ "/" + $F{EXPECTEDSTARTDATE}.getYear()+ "</b> and end on <b>"+ $F{PURCHASEAGREEMENTEXPIRATION}.getMonth()+ "/" + $F{PURCHASEAGREEMENTEXPIRATION}.getDay()+ "/" + $F{PURCHASEAGREEMENTEXPIRATION}.getYear()+ "</b>." Link to comment Share on other sites More sharing options...
gdmoreno Posted July 24, 2012 Share Posted July 24, 2012 Try the code below instead - the getYear() method unfortunately returns year minus 1900, which is why you're seeing 112 for 2012. So you have to 1900 back to the value that getYear() returns.The other solution would be to put the date in its own text field (instead of mixing it with String values like you're currently doing), and then set the pattern to MM/dd/yyyy, and the pattern would then take hold. Code:"Agreement will commence on <b>"+ $F{EXPECTEDSTARTDATE}.getMonth()+ "/" + $F{EXPECTEDSTARTDATE}.getDay()+ "/" + $F{EXPECTEDSTARTDATE}.getYear()+ "</b> and end on <b>"+ $F{EXPECTEDSTARTDATE}.getMonth()+ "/" + $F{EXPECTEDSTARTDATE}.getDay()+ "/" + String.valueOf(1900 + $F{EXPECTEDSTARTDATE}.getYear())+ "</b>." Link to comment Share on other sites More sharing options...
cbarlow3 Posted July 25, 2012 Share Posted July 25, 2012 I agree with the previous response (although I think he meant to put it in its own java.util.Date field, not a text field--the date format doesn't work if the field is still a string). If you don't like having it as a separate date field because it's too hard to embed in the middle of surrounding text, then you can also try keeping the text expression, but make it something like this:"Text before date " + new StringBuilder(new SimpleDateFormat("MM/dd/yyyy").format($F{EXPECTEDSTARTDATE})) + " and text after date."Carl Link to comment Share on other sites More sharing options...
cg8 Posted July 25, 2012 Author Share Posted July 25, 2012 I tried the previous suggestion as a separate string (with java.util.Date) and it worked, but like you said it is a bit difficult to work it into surrounding text. I will try your method Carl.Thanks for the responses so far! Link to comment Share on other sites More sharing options...
sounevil Posted August 31, 2012 Share Posted August 31, 2012 Day: new Integer($F{Fecha}.getDate())Month: new Integer($F{Fecha}.getMonth()+1)Year: new Integer($F{Fecha}.getYear()+1900) Link to comment Share on other sites More sharing options...
cg8 Posted August 31, 2012 Author Share Posted August 31, 2012 Post Edited by cg8 at 08/31/2012 16:20 Link to comment Share on other sites More sharing options...
cg8 Posted August 31, 2012 Author Share Posted August 31, 2012 I tried the method that Carl suggested and it worked perfectly. Thanks! 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