I try to subtract 30 days to current date and I always receive a negative number to day value. The most important thing is the format of the returned date, that must be
var date = new Date();
var dd = date.getDate()-30;
var mm = date.getMonth()+1;
var yyyy = date.getFullYear();
var dateTo = yyyy+'-'+mm+'-'+dd;
Because you are subtracting from a number that has NO connection to the date object. Changing it does nothing but change the number. You need to subtract the days from the date itself.
var today = new Date(); var past30 = new Date(); past30.setDate(today.getDate()-30); console.log(past30);