// function
getDate = function(dateObj){
var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay():dateObj.getDay();
var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth():dateObj.getMonth();
return dateObj.getFullYear()+'-'+month+'-'+day;
}
// example usage
console.log(getDate(new Date()));
// with custom date
console.log(getDate(new Date(2012,dateObj.getMonth()-30,dateObj.getDay()));