I am trying to call a function testAvailability from within unavailableDays.  I need to format the date as a string in selDate using dd-MM-yyyy format.  I think I am either not calling the function properly or there is a problem with my date formatting or both. 
Any thoughts?
function unavailableDays(days) {
    var i = Date.now();
    var d;
    var checkit 
    var unavailableDates = [];
    var j = i + days * 24 * 60 * 60 * 1000;
    while(i < j) {
        d = new Date(i);
        //add an if then statement here, if true push the date else no
        checkit = testAvailability("'" + d.getDate() + '-' + (d.getMonth() + 1) + '-' + (d.getYear() + 1900) + "'");
        if(checkit ===  true) {
            unavailableDates.push(d.getDate() + '-' + (d.getMonth() + 1) + '-' + (d.getYear() + 1900));
            i += 24 * 60 * 60 * 1000;
        } else {
            i += 24 * 60 * 60 * 1000;
        }
    }
    return unavailableDates;
}
var numOfDays = 60;
var populated = unavailableDays(numOfDays);
...
function testAvailability(selDate) {
    // Find the selected service duration (it is going to 
    // be send within the "postData" object).
    var selServiceDuration = 15; // Default value of duration (in minutes).
    $.each(GlobalVariables.availableServices, function(index, service) {
        if (service['id'] == $('#select-service').val()) {
            selServiceDuration = service['duration']; 
        }
    });
    // If the manage mode is true then the appointment's start 
    // date should return as available too.
    var appointmentId = (FrontendBook.manageMode) 
            ? GlobalVariables.appointmentData['id'] : undefined;
    var postData = {
        'service_id': $('#select-service').val(),
        'provider_id': $('#select-provider').val(),
        'selected_date': selDate,
        'service_duration': selServiceDuration,
        'manage_mode': FrontendBook.manageMode,
        'appointment_id': appointmentId
    };
    // Make ajax post request and get the available hours.
    var ajaxurl = GlobalVariables.baseUrl + 'appointments/ajax_get_available_hours';
    jQuery.post(ajaxurl, postData, function(response) {
        ///////////////////////////////////////////////////////////////
        console.log('Get Available Hours JSON Response:', response);
        ///////////////////////////////////////////////////////////////
        if (!GeneralFunctions.handleAjaxExceptions(response));
        // The response tells me if the date is booked (true) or not. 
        if (response.length > 0) {
           return false;
        } else {
           return true;
        }
    }, 'json');
}
 
     
    