Make sure that the month is only 1 character (or alternatively <9). Then add 0!
By lenght
var strMonth = today.getMonth(); if(strMonth .length == 1){ strMonth = "0" + strMonth ; }
By number
var strMonth = today.getMonth(); if(strMonth< 10){ strMonth= "0" + strMonth; }
Perhaps you want to avoid the variable prefix with str , since Javascript does not explicitly define types and can be confusing for the code. For example, saying that if strMonth < 10 is subtle logic, but maintenance is tricky that it confuses management.
Another way!
var strMonth = "0" + today.getMonth(); strMonth = strMonth.substring(strMonth.length-2, 2);
source share