From a driver in laravel I am sending a date to a view with the format YYYY-MM-DD
, but I can not make it appear in the daterangepicker , I understand it is a problem format, but I could not find the solution ..
For now I am passing the values through hidden fields in the form.
Using a alert
to show the value of the variable is correct, but I can not get it to load dynamically, however, further down in the callback function in the same line of code is loaded correctly.
<script type="text/javascript">
$(function() {
var start = new Date(document.getElementById("startDate").value);
var end = new Date(document.getElementById("endDate").value);
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
document.getElementById("startDate").value=start.format('YYYY-MM-DD');
document.getElementById("endDate").value=end.format('YYYY-MM-DD');
}
$('#reportrange').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')]
}
},
callback
);
function callback(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
document.getElementById("startDate").value=start.format('YYYY-MM-DD');
document.getElementById("endDate").value=end.format('YYYY-MM-DD');
}
});
</script>