1 Reply Latest reply on Sep 9, 2011 10:24 PM by kglad

    Date Suffix?  (st  / nd / rd / th etc...)

    Tony Heagren Level 1

      Hi all,

       

      I'm using a dateChooser which outputs to a dynamic text field.

      The output looks like this:

      Wednesday September 28 2011

       

      Must have been asked before but does anyone know how to add the date suffix to the number to make 28 into 28th, 1 into 1st, 3 into 3rd  etc

      and if so, how would I integrate it into this code ?

       

      var thisDate:String = dayA[d.getDay()]+" "+monthA[d.getMonth()]+" " +d.getDate() + " " +d.getFullYear();

       

      Best wishes

      Tony

        • 1. Re: Date Suffix?  (st  / nd / rd / th etc...)
          kglad Adobe Community Professional & MVP

          :

           

          var suffixA:Array = ["st","nd","rd"];

          var thisDate:String = dayA[d.getDay()]+" "+monthA[d.getMonth()]+" " +dateF(d.getDate()) + " " +d.getFullYear();



          function dateF(n:Number):String{
              var m:Number = n%10-1;
              if(m<suffixA.length && (n<4 || n>20)){
                  return n+suffixA[m];
              } else {
                  return n+"th";
              }
          }
          1 person found this helpful