var mydate = new Date(); var yester = mydate-24*60*60*1000; var yesterday = new Date(); yesterday.setTime(yester); var str = "" + yesterday.getFullYear() + "-"; if (yesterday.getMonth()>=9) { str+=(yesterday.getMonth()+1) + "-"; } else{
str +="0"+(yesterday.getMonth()+1)+"-"; } if ((yesterday.getDate())<10) { str+="0"+(yesterday.getDate()); } else{ str += (yesterday.getDate()); } $("#mydata").val(str);