Search code examples
javascripthtmlappointment

show appointments/ dates of today with JavaScript function


I want to show the actual appointments of the day in my HTML. I would like to implement it with a JavaScript where I get the name of the appointment and the date out of an excel table. I already wrote something but it doesn't work and not in the way I want it. Code:

function appointment() {

    var event = [];
    var temp = [];

    event[0] = ["17.12.2015", "test1"];
    event[1] = ["11.12.2015", "TestToday"];

    var datum = new Date();     
    var today = today.getDate();    
    var month = today.getMonth() + 1; 

    for (i = 0; i < event.length; i++) {
        if (event[i]) {
            if (event[i][0] == today && event[i][0] == month) {
                event[i][0] = temp[i];
            }
        }
        else {
            break;
        }
    }

    if (temp.length == 0) {
        document.write("Today is nothing to do");
    }
    else {
        var x2 = "Today " + ((temp.length == 1) ? "is following event: " : "are following events: ");
        for (i = 0; i < temp.length; i++) {
            x2 += ((temp[i] > 0) ? ((temp[i] == (temp.length - 1)) ? " and " : ", ") : " ") + temp[event[1]][3] + "(" + temp[event[i]][2] + ")";
        }
        document.write(x2 + " appointment");
    }

}

Question: How can I make it work? How can I read the appointment toppic and date out of a excel table?


Solution

  • Change your code to

    var datum = new Date().setHours(0,0,0,0);
    //you don't need today and month
    if (event[i]) {
       eventDate = new Date(event[i][0].split(".").reverse()).getTime();
       if (datum === eventDate) {
            temp.push(event[i][1]); //there was a problem here as well
       }
    }
    else {
       break;
    }
    

    jsFiddle