Cycle rate between two dates
-
Hello, I am working on a formula and I have reached the final point, but I could not find a solution.
My cycle is like this.
const faizOranlari = [ { baslangicTarihi: new Date("14/11/2023"), oran: 0.035 }, { baslangicTarihi: new Date("21/07/2022"), oran: 0.025 }, { baslangicTarihi: new Date("30/12/2019"), oran: 0.016 }, { baslangicTarihi: new Date("02/10/2019"), oran: 0.02 }, { baslangicTarihi: new Date("01/07/2019"), oran: 0.025 }, { baslangicTarihi: new Date("05/09/2018"), oran: 0.02 }, { baslangicTarihi: new Date("19/10/2010"), oran: 0.014 }, { baslangicTarihi: new Date("19/11/2009"), oran: 0.0195 }, { baslangicTarihi: new Date("21/04/2006"), oran: 0.025 }, { baslangicTarihi: new Date("02/03/2005"), bitisTarihi: new Date("20/04/2006"), oran: 0.03 }, { baslangicTarihi: new Date("02/01/2004"), bitisTarihi: new Date("01/03/2005"), oran: 0.04 }, { baslangicTarihi: new Date("12/11/2003"), bitisTarihi: new Date("01/01/2004"), oran: 0.04 }, { baslangicTarihi: new Date("31/01/2002"), bitisTarihi: new Date("11/11/2003"), oran: 0.07 }, { baslangicTarihi: new Date("29/03/2001"), bitisTarihi: new Date("30/01/2002"), oran: 0.1 }, { baslangicTarihi: new Date("02/12/2000"), bitisTarihi: new Date("28/03/2001"), oran: 0.05 }, { baslangicTarihi: new Date("20/01/2000"), bitisTarihi: new Date("01/12/2000"), oran: 0.06 }, { baslangicTarihi: new Date("09/07/1998"), bitisTarihi: new Date("19/01/2000"), oran: 0.12 }, { baslangicTarihi: new Date("01/02/1996"), bitisTarihi: new Date("08/07/1998"), oran: 0.15 }, { baslangicTarihi: new Date("31/08/1995"), bitisTarihi: new Date("31/01/1996"), oran: 0.1 }, { baslangicTarihi: new Date("08/03/1994"), bitisTarihi: new Date("30/08/1995"), oran: 0.12 }, { baslangicTarihi: new Date("30/12/1993"), bitisTarihi: new Date("07/03/1994"), oran: 0.09 }, { baslangicTarihi: new Date("01/01/1990"), bitisTarihi: new Date("29/12/1993"), oran: 0.07 }, { baslangicTarihi: new Date("01/01/1989"), bitisTarihi: new Date("31/12/1989"), oran: 0.1 }, { baslangicTarihi: new Date("01/06/1988"), bitisTarihi: new Date("31/12/1988"), oran: 0.1 }, { baslangicTarihi: new Date("01/09/1985"), bitisTarihi: new Date("31/05/1988"), oran: 0.1 }, { baslangicTarihi: new Date("01/03/1984"), bitisTarihi: new Date("31/08/1985"), oran: 0.1 }, { baslangicTarihi: new Date("01/01/1981"), bitisTarihi: new Date("29/02/1984"), oran: 0.1 } ];
This loop helps me get rates between dates.
a) User selects start and end date.
I want to find the total rate between the dates (months) selected by the user.
For example ; I find that there are 110 months and 10 days between 01/01/2015 and 11/03/2024
Now, taking into account the dates in the cycle, I want to find and sum the ratio of each month between the cycle dates.
The total rate should be 195.10%.
But my formula adds by taking constant values. I am sharing my code with you.
(function() { var kriter5 = ''; const faizOranlari = [ { baslangicTarihi: new Date("14/11/2023"), oran: 0.035 }, { baslangicTarihi: new Date("21/07/2022"), oran: 0.025 }, { baslangicTarihi: new Date("30/12/2019"), oran: 0.016 }, { baslangicTarihi: new Date("02/10/2019"), oran: 0.02 }, { baslangicTarihi: new Date("01/07/2019"), oran: 0.025 }, { baslangicTarihi: new Date("05/09/2018"), oran: 0.02 }, { baslangicTarihi: new Date("19/10/2010"), oran: 0.014 }, { baslangicTarihi: new Date("19/11/2009"), oran: 0.0195 }, { baslangicTarihi: new Date("21/04/2006"), oran: 0.025 }, { baslangicTarihi: new Date("02/03/2005"), bitisTarihi: new Date("20/04/2006"), oran: 0.03 }, { baslangicTarihi: new Date("02/01/2004"), bitisTarihi: new Date("01/03/2005"), oran: 0.04 }, { baslangicTarihi: new Date("12/11/2003"), bitisTarihi: new Date("01/01/2004"), oran: 0.04 }, { baslangicTarihi: new Date("31/01/2002"), bitisTarihi: new Date("11/11/2003"), oran: 0.07 }, { baslangicTarihi: new Date("29/03/2001"), bitisTarihi: new Date("30/01/2002"), oran: 0.1 }, { baslangicTarihi: new Date("02/12/2000"), bitisTarihi: new Date("28/03/2001"), oran: 0.05 }, { baslangicTarihi: new Date("20/01/2000"), bitisTarihi: new Date("01/12/2000"), oran: 0.06 }, { baslangicTarihi: new Date("09/07/1998"), bitisTarihi: new Date("19/01/2000"), oran: 0.12 }, { baslangicTarihi: new Date("01/02/1996"), bitisTarihi: new Date("08/07/1998"), oran: 0.15 }, { baslangicTarihi: new Date("31/08/1995"), bitisTarihi: new Date("31/01/1996"), oran: 0.1 }, { baslangicTarihi: new Date("08/03/1994"), bitisTarihi: new Date("30/08/1995"), oran: 0.12 }, { baslangicTarihi: new Date("30/12/1993"), bitisTarihi: new Date("07/03/1994"), oran: 0.09 }, { baslangicTarihi: new Date("01/01/1990"), bitisTarihi: new Date("29/12/1993"), oran: 0.07 }, { baslangicTarihi: new Date("01/01/1989"), bitisTarihi: new Date("31/12/1989"), oran: 0.1 }, { baslangicTarihi: new Date("01/06/1988"), bitisTarihi: new Date("31/12/1988"), oran: 0.1 }, { baslangicTarihi: new Date("01/09/1985"), bitisTarihi: new Date("31/05/1988"), oran: 0.1 }, { baslangicTarihi: new Date("01/03/1984"), bitisTarihi: new Date("31/08/1985"), oran: 0.1 }, { baslangicTarihi: new Date("01/01/1981"), bitisTarihi: new Date("29/02/1984"), oran: 0.1 } ]; const baslangicTarihi = new Date("01/01/2015"); const bitisTarihi = new Date("11/03/2024"); let toplamFaizOrani = 0; let currentMonth = new Date(baslangicTarihi); while (currentMonth <= bitisTarihi) { for (let i = 0; i < faizOranlari.length; i++) { const faizOrani = faizOranlari[i]; const baslangic = faizOrani.baslangicTarihi.getTime(); const bitis = faizOrani.bitisTarihi ? faizOrani.bitisTarihi.getTime() : Number.POSITIVE_INFINITY; if (currentMonth.getTime() >= baslangic && currentMonth.getTime() < bitis) { toplamFaizOrani += faizOrani.oran; break; } } currentMonth.setMonth(currentMonth.getMonth() + 1); } kriter5 = (toplamFaizOrani * 100).toFixed(2) + "%"; jQuery('#calculation-kriter5').html(kriter5); jQuery('.kriter5-aciklama').html('Faiz Oran?: '); jQuery('.kriter5-sonuc').html(kriter5); return [kriter5]; })();
I wonder where the error is? Can you help me?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Cycle rate between two dates’ is closed to new replies.