Jump to content
We've recently updated our Privacy Statement, available here ×

Date not appearing correctly (i.e. "7/3/112" instead of "7/3/2012")


cg8

Recommended Posts

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 Properties

Expression Class: java.lang.String

Pattern: MM/dd/yyyy

Text 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

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 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

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

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

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...