HELPME
HELPME

Reputation: 754

Cannot read property 'getTime' of undefined error

I know there were a lot of questions related to this, but I couldn't find information that would help... I just need to solve this problem in my script, does anyone could help me with that?

function dateValidation() {

this.validateDate = function() {
    var twoDates = {
        inputDate: $('#employmentDate').val(),
        todaysDate: new Date()
    }
    return twoDates.inputDate.getTime() < twoDates.todaysDate.getTime();
}
}
var validation = new dateValidation();
validation.validateDate();

This error I'm getting on the line 8:

return twoDates.inputDate.getTime() < twoDates.todaysDate.getTime();

Thank you

Upvotes: 2

Views: 8297

Answers (1)

Niklesh Raut
Niklesh Raut

Reputation: 34914

Create Date object instead string, Change this line

inputDate: $('#employmentDate').val(),

To

inputDate: new Date($('#employmentDate').val()),

Upvotes: 2

Related Questions