I've written the following code.
var start = moment().subtract(1, 'days');
var end = moment().subtract(1, 'days');
var start2 =moment().subtract(2, 'days');
var end2 =moment().subtract(2, 'days');
function cb(start, end, start2, end2) {
console.log(start2);
$('#reportrange3 span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
$('#reportrange4 span').html(start2.format('MMMM D, YYYY') + ' - ' + end2.format('MMMM D, YYYY'));
retrievedata(start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD'),start2.format('YYYY-MM-DD'), end2.format('YYYY-MM-DD') );
}
$('#reportrange3').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
$('#reportrange4').daterangepicker({
startDate: start2,
endDate: end2,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end, start2, end2);
The problem I've got is that updating the values of both reportrange, the console.log(start2) returns a text value, such as "Today" or "Yesterday", so it ends with an error as "today".format('MMMM D, YYYY') does not really work...
Any idea? Thanks!
Finally I've found the solution, the problem was coming from variables scope.