I have a funny bug in my calculation about interest days. I go through each day and check which day it is (1 to 31). Now I found a problem: In October the count doesn't work properly. That means the 27th is the 26th, or the 29th is the 28th. Is this a well know problem? Maybe the problem is in my code, but, because it works over another period, it seems to be fine.
    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
        function berecheZinstage() {
            //eingabe von den Feldern holen
            var strVon = txtVonDatum.value;
            var strBis = txtBisDatum.value;
            //label um das Resultat anzuzeigen
            var resultatTage = document.getElementById("lblTage");
            var resultatZinsTage = document.getElementById("lblZinstage");
            //tag als Milisekunden
            var tagMs = 86400000;
            var monatCount;
            //Eingabeformat umwandeln für die Berechung
            strVon = strVon.replace(/-/g, "/");
            strBis = strBis.replace(/-/g, "/");
            var vonDatum = new Date(strVon);
            var bisDatum = new Date(strBis);
            var zinsTage = 0;
            if (bisDatum > vonDatum) {
                var totTage = bisDatum - vonDatum;
                var nDays = Math.round(totTage / (1000 * 60 * 60 * 24));
                var pruefMS = vonDatum.getTime();
                var startMS = vonDatum.getTime();
                var endeMS = bisDatum.getTime();
                var febCount = 0;
                var langCount = 0;
                var tage = 0;
                for (var i = 0; i < nDays; i++) {
                   pruefMS = pruefMS + tagMs;
                   var pruefDatum = new Date(pruefMS);
                    var pruefMonat = pruefDatum.getMonth();
                    var pruefJahr = pruefDatum.getFullYear();
                    var pruefTag = pruefDatum.getDate();
                    if (pruefTag == 1 && pruefDatum != startMS) {
                        if (pruefMonat == 2) {
                            var istSchaltjahr = new Date(pruefJahr, 1, 29).getMonth() == 1;
                            if (istSchaltjahr) {
                                tage++;
                            }
                            else {
                                tage = tage + 2;
                            }
                        }
                    }
                    if (pruefTag != 31) {
                        tage++;
                    }
                }
                resultatZinsTage.innerText = tage.toString();
                resultatTage.innerText = pruefTag;//nDays.toString();
            }
            else {
                resultatTage.innerText = "Bis Datum muss grösser sein als von Datum";
            }
        }
    </script>
    <title>Zinstage berechen</title>
</head>
<body>
    <table style="width:100%;">
        <tr>
            <td style="width:100px;"><input id="txtVonDatum" type="text" /></td>
            <td style="width:100px;"><input id="txtBisDatum" type="text" /></td>
            <td style="width:100px;"><button id="btnCalcDays" type="button" onclick="berecheZinstage();">Berechnen</button></td>
            <td> </td>
        </tr>
        <tr>
            <td>Tage:</td>
            <td><label id="lblTage"></label></td>
            <td> </td>
            <td> </td>
        </tr>
        <tr>
            <td>Zinstage:</td>
            <td><label id="lblZinstage"></label></td>
            <td> </td>
            <td> </td>
        </tr>
    </table>
</body>
</html>
Thanks, Marlowe
 
     
    