Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i just want to ask how to compare dates with the following scenario:

1. i have two textboxes that has date picker. [textbox1] and [textbox2]
2. [textbox2] Date must not be less than the date inside [textbox1]

is there any javascript to do it?

thanks.

[UPDATE] [textbox1] Date should not be less than the current date.
Posted
Updated 13-Aug-13 19:52pm
v2

 
Share this answer
 
Hello

Try to below code


C#
var xDate=new Date();
xDate.setFullYear(2100,0,14);
var today = new Date();

if (xDate>today)
  {
  alert("Today is before 14th January 2100");
  }
else
  {
  alert("Today is after 14th January 2100");
  }


Thanks
 
Share this answer
 
Hi,

Please Try This one you can get solution (make changes as per your code).



C#
function datevalidate2(dateFrom, dateTo)
  {
       var arr = dateFrom.split("-");
       var Fyear=arr[0];
       var Fmonth=arr[1];
       var Fday=arr[2];
       var arr1=dateTo.split("-");
       var Tyear=arr1[0];
       var Tmonth=arr1[1];
       var Tday=arr1[2];

       if(parseInt(Fyear)>parseInt(Tyear))
       {
           return false;
       }
       else if (parseInt(Fyear) == parseInt(Tyear) && parseInt(Fmonth) > parseInt(Tmonth))
       {
           return false;
       }
       else if (parseInt(Fyear) == parseInt(Tyear) && parseInt(Fmonth) == parseInt(Tmonth) && parseInt(Fday) > parseInt(Tday))
       {
           return false;
       }
       return true; 
  }
 
Share this answer
 
v2
constructed codes for that:

here it is

C#
$(document).ready(function () {
         $("[id$=sa_start]").datepicker({
             minDate: 0,
             maxDate: "+60D",
             numberOfMonths: 2,
             dateFormat: 'MM-dd-yy',
             onSelect: function (selected) {
                 $("[id$=sa_end]").datepicker("option", "minDate", selected)
             }
         });

         $("[id$=sa_end]").datepicker({
             minDate: 0,
             maxDate: "+60D",
             numberOfMonths: 2,
             dateFormat: 'MM-dd-yy',
             onSelect: function (selected) {
                 $("[id$=sa_start]").datepicker("option", "maxDate", selected)
             }
         });
     });
 
Share this answer
 
JavaScript
var startDate=Date.parse($("#id_of_start_date_text_box").val());
var endDate=Date.parse($("#id_of_end_date_text_box").val());
if(startDate>endDate)
{
   alert("Sorry! start date can't be greater than end date.Please provide valid dates.");
}
else
{
  //Do your stuffs...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900