4 Replies Latest reply: Oct 10, 2012 6:29 AM by Ben Rogers RSS

    how to display date suffixes st, nd, rd and th for different days

    966393
      Hi all,

      My first post here, so please bare with me if I've not followed any guidelines, please point out if there are any.

      My question is how would you display the suffix that goes with a certian day of the month.

      For example, st for the 1st of the month, nd for 2nd and so on...

      My initial thought is a rules table that would append the relevant suffix based on the day value.

      Does anyone have any other ideas.

      Thanks in advance.
        • 1. Re: how to display date suffixes st, nd, rd and th for different days
          Ben Rogers
          Hello and welcome to the forum!

          If you want to change the way your dates are displayed in OPA you can add the following to your application.properties file (in the Release/web-determinations/WEB-INF/classes/configuration/ folder)
          output-date-format           =EEE\, d MMM yyyy
          This will give you a date of Fri, 5 Oct 2012.
          More examples here:
          http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html

          (remember to put an escape character \ before a comma)

          However I don't think you can tweak this to display "th", "st" etc.
          Fri, 5 Oct 2012 is probably user-friendly enough and is very simple to implement... OPA can do the hard work for you and there is no code to maintain.

          To do this in rules you could, as you say, do it in a rules table in Word or even in an Excel sheet...
          However you would have to build a string for each date attribute that you use in the rulebase (or each date that you want to format). You could just have an excel tab for each date field and tuck it away deep in your system rules folder :-) Or you could even write a custom function that instantly builds the date string with the suffixes how you want them, and then you could have one document which then assigns these to text string for each date attribute.

          If you can tweak the application.properties to display dates that you want then I'd say that's your best option but as long as you keep the rulebase organised it should be ok to use rule tables...unless anyone else knows of a way to automatically display the suffixes by tweaking the application.properties?

          Cheers
          Ben
          • 2. Re: how to display date suffixes st, nd, rd and th for different days
            Ian Clough
            A possible solution is to implement a custom formatter written in Java (or .Net), this is fairly straight forward for output but you also need parse date inputs in the same format assuming these dates may be displayed as text input fields on screens rather than just labels. The online help has a good introduction and there is also some sample code, just search for 'custom format'.
            • 3. Re: how to display date suffixes st, nd, rd and th for different days
              967403
              thanks for the responses.

              at the moment, this is only limited to one date, and I actually just need to show the day, not the whole date, so I've just used a rules table.

              very interesting suggestions, though, so thanks for your help.
              • 4. Re: how to display date suffixes st, nd, rd and th for different days
                Ben Rogers
                No problem!

                You're right, if you only need to do it for one date and just need the day then by far the simplest and most maintainable solution is to use a rule table.

                Happy rule writing!

                Cheers,
                Ben