Avoid cascading of if’s
var month = ["January", "Feb", "March",....,"Dec"];//store array of months as string
var suffix =["st","nd","rd","th"];
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getFullYear();
var op="";
if(parseInt(dd) > 4)
op+=dd+""+suffix[3]+"|";
else
op+=dd+""+suffix[(parseInt(dd)%10)-1]+"|";
op+=month[parseInt(mm)]+"|"+yyyy;
MAKE IT SIMPLE working fiddle
FYI : just now saw the answer and 0-11 for months while 0
represents Jan and 11 represents Dec
solved Why does this Javascript script not give ant output?