vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, June 18, 2012

Compare two dates using JavaScript in asp.net



Here we see the code about two compare two date using JavaScript. In dotnet application we can easily compare the two date using server side. But in some instance
We need do comparison without post back conditioning such case JavaScript would help to check the date in client side. The main advantage of using JavaScript it reduces the Load on webserver.
Code:
function cmpdate() {
          var d1 = new Date();
          d1 = "18/06/2012";
          //Here you can get enter date from the control like below
          //d1= document.getElementById('ddl1').value;
          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;

          if (d1 < today) {

              alert("Enter date is less then present date");
          }
          //*********code by www.dotnetcode.in*************
          //***********************************************
      }

Happy coding…

0 comments:

Post a Comment