Nithesh Narayanan
Nithesh Narayanan

Reputation: 11755

Date comparison in Jquery

I want to compare the selected date and current date. Iam using jquery date picker. While using the following code only the date field comparison is takes place... How can i compare with month and year also... Advance thanks..

$(document).ready(function() {



        var objDate = new Date();
        var selectedDate = document.getElementById("<%=txtRqstDate.ClientID %>").value;

        var currentDate = $.datepicker.formatDate('dd/mm/yy', new Date());
        if (Date.parse(selectedDate) > Date.parse(currentDate )) {
            alert("Invalid date range!\n Please choose a date that is not later than today!")
            return false;
        }
        else {
            return true;
        }

Upvotes: 1

Views: 6242

Answers (1)

kbvishnu
kbvishnu

Reputation: 15630

Pls use this.I thing it will solve ur problem

function ChDate(){
 var objDate = new Date();
 var selectedDate = document.getElementById("<%=txtRqstDate.ClientID %>").value;

if (selectedDate > objDate ) {
  //do
}
else
{
 //do
}
}

Pls chk the following link to get more functions http://www.w3schools.com/jsref/jsref_obj_date.asp It is possible to take split an do checking by using string.split(separator, limit)

Upvotes: 2

Related Questions