Without re-inventing the wheel, datatables has every need you might require - pagination, rows per page, search option, headers etc. all in one go.
READ MORE here from their documentation with sample code for each function in javascript/ajax.
To calculate the difference between 2 dates, use something like this -
<pre lang="Javascript">
const date1 = new Date('7/13/2010');
const date2 = new Date('12/15/2010');
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffTime + " milliseconds");
console.log(diffDays + " days");
To create teh array AFTER the dates calculation was done, do thi -
var mydates = new Array();
mydates.push(["01.01.2020"]);
mydates.push(["02.01.2020"]);
mydates.push(["03.01.2020"]);
To change the header "text", you can use something like this -
headerCell.innerHTML = dates[0][i];
row.appendChild(headerCell);