Using javascript array inside $("tr:contains('"+array+"')")

Question:

I have 3 functions, to make the date range filter in a range of 2.

It's like this, I have a start date and an end date, and within these two dates it looks in a table within its three and all such dates that will be in this range.

The functions used to make this range (which is stored in an array):

// prototype of dates
Date.prototype.addDays = function(days) {
    var dat = new Date(this.valueOf())
    dat.setDate(dat.getDate() + days);
    return dat;
}

//GET DATES INTERVAL FUNCTION
function getDates(startDate, stopDate) {
    var dateArray = new Array();
    var currentDate = startDate;
    while (currentDate <= stopDate) {
        dateArray.push( new Date (currentDate) )
        currentDate = currentDate.addDays(1);
    }
    return dateArray;
}

And here where the change occurs that triggers these functions and inside it I want you to look for this date range that I need:

$("#start").keydown(function(event) {

        var d1 = new Date($(this).val());
        var d2 = new Date($("#end").val());

        console.log(getDates(d1,d2));
    });

    $("#end").keydown(function(event) {

        var d1 = new Date($("#start").val());
        var d2 = new Date($(this).val());

        console.log(getDates(d1,d2));
    });

Answer:

Solution:

//GET DATES INTERVAL FUNCTION
function getDates(startDate, stopDate) {
var dateArray = new Array();

var currentDate = startDate;

while (currentDate <= stopDate) {

  var newDate = currentDate;

  var res = newDate.toString().split('-');

  res = res[0].toString().split(' ');
  res = res[2] + '/' + monthToNumber(res[1]) + '/' + res[3];

  dateArray.push( res );

  currentDate = currentDate.addDays(1);

}

return dateArray;
}

$("#start").keydown(function(event) {

    var d1 = new Date($(this).val());


    var d2 = new Date($("#end").val());

    console.log(getDates(d1,d2));

});

$("#end").keydown(function(event) {

    var d1 = new Date($("#start").val());
    var d2 = new Date($(this).val());

    console.log(getDates(d1,d2));

});
Scroll to Top