Please submit dates in this format: YEAR-MONTH-DAY. Example: 2019-01-29
Move in:
Move out:
Deposit:
var perc = 0.01; var totalMidYears = 0; var tempTotal = 0; var count = 1;
var apr = new Array(); apr[2000] = 5; apr[2001] = 2; apr[2002] = 0; apr[2003] = 1; apr[2004] = 0.26; apr[2005] = 1.21; apr[2006] = 1.74; apr[2007] = 2.39; apr[2008] = 3.22; apr[2009] = 1.76; apr[2010] = 0.55; apr[2011] = 0.29; apr[2012] = 0.22; apr[2013] = 0.15; apr[2014] = 0.18; apr[2015] = 0.12; apr[2016] = 0.06; apr[2017] = 0.07; apr[2018] = 0.07; apr[2019] = 0.06; apr[2020] = 0.23; apr[2021] = 0.06;
function myFunction() { var fyInterest = 0; var lyInterest = 0; var totalMidYears = 0; var rounded1 = 0; var rounded2 = 0;
var x = document.getElementById("mid").value; var y = document.getElementById("mod").value; var z = document.getElementById("dep").value;
//temp //x="2018-01-15"; //y="2018-12-31"; //z=1895;
var midYearOnly = parseInt(x); var modYearOnly = parseInt(y);
//-- Calc days from moving in till e-o-y ------------------------------------------------
if (midYearOnly < modYearOnly){
var startDate = Date.parse(x);
var eoyString = midYearOnly + "-12-31";
var eoy = Date.parse(eoyString);
var timeDiff = eoy - startDate;
var fyTotalDays = 1 + Math.floor(timeDiff / (1000 * 60 * 60 * 24));
fyInterest = (((fyTotalDays * apr[midYearOnly])/365) * perc) * z;
var roudedString1 = fyInterest.toFixed(2);
rounded1 = Number(roudedString1);
//alert("First: " + rounded1);
}
//-- Calc days from b-o-y till move out -------------------------------------------------
var endDate = Date.parse(y);
var boyString = modYearOnly + "-01-01";
var boy = Date.parse(boyString);
var lyDays = endDate - boy;
var lyTotalDays = 1 + Math.floor(lyDays / (1000 * 60 * 60 * 24));
var lyInterest = ((((lyTotalDays + 1) * apr[modYearOnly])/365) * perc) * z;
var roudedString2 = lyInterest.toFixed(2);
rounded2 = Number(roudedString2);
//alert("Last: " + rounded2);
//-- Calc from m-i-y to m-o-y ------------------------------------------------------------
while (midYearOnly + count < modYearOnly) {
tempTotal = (apr[midYearOnly + count] * perc) * z;
var roudedString3 = tempTotal.toFixed(2);
var rounded3 = Number(roudedString3);
// alert(rounded3);
totalMidYears = totalMidYears + rounded3;
count = count + 1;
//alert(midYearOnly + count - 1 + " " + rounded3);
}
//-- Add all years and output ------------------------------------------------------------
var totalInterest = rounded1 + rounded2 + totalMidYears;
alert("Total interest amount: $" + totalInterest);
}