1

I have been trying to workout a script to add ordinal suffixes to my date script (seen below), but all attempts to write one or search on here for one has alas failed. Any insight to help fix the script would be greatly appreciated.

https://jsfiddle.net/wq5t4gh7/1/

var months = ["Month1", "Month2", "Month3", "Month4", "Month5", "Month5", "Month7", "Month8", "Month9", "Month10", "Month11", "Month12"];
var n = new Date();
var y = n.getFullYear().toString().substr(2,2);;
var m = n.getMonth();
var d = n.getDate();

document.getElementById("date").innerHTML = "The " + d + " of " + months[m] + ", 52" + y;
Rhmul
  • 27
  • 2
  • Possible duplicate of [JavaScript new Date Ordinal (st, nd, rd, th)](http://stackoverflow.com/questions/15397372/javascript-new-date-ordinal-st-nd-rd-th) – Felix Eve Feb 01 '17 at 23:59

1 Answers1

0

Might help

function nth(d) {
  if(d>3 && d<21) return 'th';
  switch (d % 10) {
        case 1:  return "st";
        case 2:  return "nd";
        case 3:  return "rd";
        default: return "th";
    }
} 
Mark Baker
  • 209,507
  • 32
  • 346
  • 385