rcweb
rcweb

Reputation: 73

How to convert date json to php

I have a problem receiving the date in PHP page

i send date with getJSON function from html page to php page

this code in js


var start = moment().subtract(29, 'days');
var end = moment();
    
function cb(start, end) {
    $('#reportrange span')
        .html(start.format('MMMM D, YYYY') 
            + ' - ' 
            + end.format('MMMM D, YYYY')
        );
}
    
$('#reportrange').daterangepicker({
    startDate: start,
    endDate: end,
    ranges: {
            'last 7 day': [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).on('apply.daterangepicker', function (ev, picker) {
            var startDate = picker.startDate.format('YYYY-MM-DD');
            var endDate = picker.endDate.format('YYYY-MM-DD');
            // alert(`startDate = ${startDate}, endDate = ${endDate}`);
            
            $.getJSON("getdata.php", {startDate: startDate },function (result) {
                // your result function
                $('#data').html(result);
        });
});
    
cb(start, end);

I tried with the following code but it didn't work

if (isset($_GET['startDate'])) {
    $startDate = $_GET['startDate'];
    echo   $startDate;
    exit;
}

when user select rang date i want send start and end date to php page to select data between this dates.

I tried sending other data and it appears, but when sending a date it does not appear.

Upvotes: 0

Views: 59

Answers (0)

Related Questions