Test

Test

  • NA
  • 58
  • 49.7k

unable to perform date validation using jquery

Sep 20 2019 1:09 AM
I have a text box where i will be giving the date in text box and i need to compare that given date in text box with todays date it working for past date which is the expected reult but if i am giving future date its still showing me the validation instead of inserting the date.How can i resolve this issue
Below is my code that i have used
var currentdate = new Date();
var todayDate = (currentdate.getMonth() + 1) + "/" + currentdate.getDate() + "/" + currentdate.getFullYear();
if ($("#txtDate").val() < todayDate) //txtdate is 10/20/2019 and today date is 09/20/2019 but still i am getting validation which should not happen
{
MessageDisp('divAlertMessage', "Date Cannot Be Less Than Today's Date.", 'Error');
return false;
}

Answers (5)