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

Hi guys how to put ordinal numbers in the day?


tetsuphyxia
Go to solution Solved by C-Box,

Recommended Posts

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

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 helps
Best of luck

Link to comment
Share on other sites

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 + regards

C-Box

Link to comment
Share on other sites

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...