3

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?

nolags
  • 633
  • 1
  • 11
  • 30

2 Answers2

1

Issue is in your for loop. To compare today's date should be in dd.mm.yy format as it is in array:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!

var yyyy = today.getFullYear();
if(dd<10)
    dd='0'+dd;

if(mm<10)
    mm='0'+mm;

var today = dd+'.'+mm+'.'+yyyy;

for (i = 0; i < event.length; i++) {
    if (event[i]) {
        if (event[i][0] == today) {
            temp[i] = event[i][0];
        }
    }
    // Don't break your for loop

}

Working Fiddle

void
  • 36,090
  • 8
  • 62
  • 107
1

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

Minato
  • 4,383
  • 1
  • 22
  • 28