Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing dates in jquery

I am having the following codes and it though i'm having 01-Jan-2009 for DateTo and 03-Jan-2009 for DateFrom it's reading the values as NAN. Am I missing anything? I`m referencing

 var DateToValue = $("#DateTo").val();
      var DateFromValue = $("#DateFrom").val();

      if (Date.parse(DateToValue) <= Date.parse(DateFromValue)) {
          $("#DateFrom").val(DateToValue)
      }
  <script src="@Url.Content("~/Scripts/jquery-1.4.2.min.js")"
 type="text/javascript"></script>

 <script  src="@Url.Content("~/Scripts/jquery.datePicker.js")"
type="text/javascript"></script>

         <script src="@Url.Content("~/Scripts/jquery.validate.js")"
 type="text/javascript"></script>
like image 939
learning Avatar asked Feb 15 '11 06:02

learning


2 Answers

How about this?

  DateTime DateToValue = $("#DateTo").val();
  DateTime DateFromValue = $("#DateFrom").val();

  if (Date.parse(DateToValue) <= Date.parse(DateFromValue)) {
      $("#DateFrom").val(DateToValue)
  }
like image 87
Johnny DropTables Avatar answered Sep 30 '22 03:09

Johnny DropTables


The Easy Way to Do is

 var start= new Date($('#txtstart').val());
 var end= new Date($('#txtend').val());
            if (start < end) {

            }
like image 39
Vishal Sharma Avatar answered Sep 30 '22 01:09

Vishal Sharma