Sostituisci

codice:
all = dates+what+"-"+nameofmonth+"-"+years;
con

codice:
all = dates < 10 ? "0" + dates +"-"+nameofmonth+"-"+years : dates +"-"+nameofmonth+"-"+years;