Aenik Shah
Aenik Shah

Reputation: 55

AgendaWeek Time slots always shows default value i.e 00.00.00 (hour:minute:second)

I have implemented full calendar with default view as agendaWeek. My motive here is to get date and time of clicked slot in calendar. So as an implementation I have done below code in calendar.js file:

dayClick: function (date, allDay, jsEvent, view) {
        var now = new Date();
        var targetDate = new Date();          
        targetDate.setDate(targetDate.getDate() + 10);
        if ((date.setHours(0, 0, 0, 0) < now.setHours(0, 0, 0, 0)) || (date.setHours(0, 0, 0, 0) > targetDate.setHours(0, 0, 0, 0))) {
            alert("Wrong slot of booking!!!");
        }
        else {
            console.log(date);
            alert(date.getDate()+','+ (date.getMonth()+1) +',' + date.getYear());                
        }
     },

So in console it shows me date correct but time is 00:00:00. Screenshot So it would be great if anyone help me in this issue.

Upvotes: 2

Views: 199

Answers (1)

Alok Patel
Alok Patel

Reputation: 8022

You're getting clicked date and time from "date" parameter and you are setting is to (0,0,0,0) through following function.

date.setHours(0, 0, 0, 0)

Get a clone of that variable and use it to check for your conditions.

Make sure you clone that variable not just passing the reference. I hope that will solve your issue.

Upvotes: 1

Related Questions