tetsuphyxia Posted November 10, 2019 Share Posted November 10, 2019 new SimpleDateFormat("d").format(new java.util.Date())this is my expression and i want to put ordinal numbers in the day Link to comment Share on other sites More sharing options...
C-Box Posted November 11, 2019 Share Posted November 11, 2019 you mean to get the number of your resulting String??? .... something likeInteger.parseInt(new SimpleDateFormat("d").format(new java.util.Date()))[/code]??regardsC-Box Link to comment Share on other sites More sharing options...
tetsuphyxia Posted November 11, 2019 Author Share Posted November 11, 2019 I want to show the ordinal like 1st 2nd 3rd 4th 5th beacuase i was making a certificate in jasper reportfor example the day tomorrow is 12 so i want to display 12th Link to comment Share on other sites More sharing options...
joseng62 Posted November 13, 2019 Share Posted November 13, 2019 Hi tetsuphyxia, So I looked into if there is a current lib that can assist you with this, but my search has resulted with no given lib, execpt that you would need to write a custom class to handle this for you. Seem that SimpleDateFormat or DateTimeFormatter would not be able to give you your final annswer. So write that jar which would return a result, deploy jar to you're jasperstudio, call you class in a textfield and pass the new SimpleDateFormat("d").format(new java.util.Date() to you jar. Seems to be the only way. Hope this helpsBest of luck Link to comment Share on other sites More sharing options...
tetsuphyxia Posted November 13, 2019 Author Share Posted November 13, 2019 Thank you for the response sir. Im just a newbee in jasperstudio :) Do you have screenshot or examples how to do that? Link to comment Share on other sites More sharing options...
C-Box Posted November 14, 2019 Share Posted November 14, 2019 You won't need any external library nor a scriptlet or tools class.....Here an quick and dirty solution 1. Create a report variable e.g. named "DayAsInt" that just returns the day of the month as Integer with that as variable expression (just to shorten the next step a bit):Integer.parseInt(new SimpleDateFormat("d").format(new java.util.Date()))[/code]2. Create a second String variable e.g named "OrdDay" with that as variable expression (looks complex but is just a simple If-Then-Else concat way):$V{DayAsInt} == 1 || $V{DayAsInt} ==21 || $V{DayAsInt} == 31? $V{DayAsInt}+"st" : $V{DayAsInt} == 2 || $V{DayAsInt} == 22 ? $V{DayAsInt}+"nd" : $V{DayAsInt} == 3 || $V{DayAsInt} == 23 ? $V{DayAsInt}+"rd" : $V{DayAsInt} + "th"[/code]In your textfields you can now use that second concated String variable $V{OrdDay} of course the charme of a tools class would be easier for reuse that logic in multiple reports without defining those two variables again... but for a first quick-and-dirty way it probably works :-)Hth + regardsC-Box Link to comment Share on other sites More sharing options...
tetsuphyxia Posted November 14, 2019 Author Share Posted November 14, 2019 Hello C-box i tried your suggestion, I created a two variable which is DayAsint and OrdDay then i called the ordDay variable in my textfield but the output was null Link to comment Share on other sites More sharing options...
tetsuphyxia Posted November 14, 2019 Author Share Posted November 14, 2019 when i tried the Integer.parseInt(new SimpleDateFormat("d").format(new java.util.Date())) the out put is d14 Link to comment Share on other sites More sharing options...
Solution C-Box Posted November 14, 2019 Solution Share Posted November 14, 2019 Hmmm something you are doing wrong... I just created a test with the EXACT suggested expressions by my first post:Works like a charm:see JRXML attached.hth + regardsC-Box Link to comment Share on other sites More sharing options...
tetsuphyxia Posted November 15, 2019 Author Share Posted November 15, 2019 Thank you for the help guys specially C-Box, it works now bro haha last time the reset type of my variable was Report so i changed it to none and it works. Thanks Link to comment Share on other sites More sharing options...
C-Box Posted November 15, 2019 Share Posted November 15, 2019 You're welcome - fine that it is working now!regards + have a nice day!C-Box 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