My goal is to determine the number of days between two dates stored in an array.
For example:
StartDate = new Array("08 Feb 1954", "16 Sep 1955", "25 Nov 1955",
"19 Oct 1956", "13 Jun 1958", "08 Aug 1958",
"05 Sep 1958", "02 Jan 1959", "19 Jun 1959",
"07 Aug 1959", "03 Nov 1959", "11 Dec 1959",
"15 Apr 1960", "20 May 1960", "21 Oct 1960",
"11 Nov 1960", "20 Dec 1960");
EndDate = new Array("26 Aug 1955", "28 Oct 1955", "07 Sep 1956",
"23 Nov 1956", "25 Jul 1958", "22 Aug 1958",
"07 Nov 1958", "17 Apr 1959", "31 Jul 1959",
"02 Oct 1959", "04 Dec 1959", "25 Dec 1959",
"13 May 1960", "10 Jun 1960", "04 Nov 1960",
"18 Nov 1960", "14 Feb 1961");
for ( var i = 0; (i < 17); i++ )
{
numdays = date_diff_indays(StartDate[i], EndDate[i]);
TotalDays += numdays;
}
I am exploring how to transform the StartDate
and EndDate
arrays into a multidimensional array for calculations.
Here is my current calculation approach:
var date_diff_indays = function (date1, date2)
dt1 = new Date(date1);
dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) -
Date.UTC(dt1.getFullYear(), dt1.getMonth(),dt1.getDate())) / (1000 * 60 * 60 * 24))
How can I iterate through the array to find the days between the dates and sum them up for a total count of days?