Below method will return true or false
false means room is already booked
true means room is available
var validationflag=CheckAvailabbleRooms("4/30/2018 1:10 AM", "4/30/2018 2:10 AM", "room1");
function CheckAvailabbleRooms(startdatea, endates, roomss)
{
var val_flag = true;
var companySiteUrlLink = titanForWork.getQueryStringParameter("CompanySiteUrl");
var startdateaes = new Date(startdatea);
var tStart = startdateaes.toISOString();
var endatestv = new Date(endates);
var vEnd = endatestv.toISOString();//EndDate
var filterData = "&$filter=EndDate ge datetime'" + tStart + "' and Rooms eq '" + roomss + "'";
var listName = 'ListName';
var siteURL = companySiteUrlLink + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=ID,Title,Rooms,Location,EventDate,EndDate" + filterData;
console.log(siteURL);
$.ajax({
url: siteURL,
headers: { Accept: "application/json;odata=verbose" },
async: false,
success: function (data) {
var items = data.d.results;
// alert(items.length);
for (var index = 0; index < items.length ; index++) {
if (items[index].EventDate <= vEnd) {
val_flag = false;
var uuu = new Date(items[index].EventDate);
console.log(items[index].ID + "-------" + uuu);
}
}
}, eror: function (data) {
console.log($('#txtSomethingWentWrong').val());
}
});
return val_flag;
}