Comparing dates in jquery

前端 未结 7 1649
鱼传尺愫
鱼传尺愫 2020-12-10 04:08

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 readi

相关标签:
7条回答
  • 2020-12-10 04:20

    I think my answer is late, tell me if it is better or not as only this worked for me in v1.10:

    if($('#DateTo').val().split("/").reverse().join("") <= 
    $('#DateFrom').val().split("/").reverse().join("")){//Do something}
    
    0 讨论(0)
  • 2020-12-10 04:24

    How about this?

      DateTime DateToValue = $("#DateTo").val();
      DateTime DateFromValue = $("#DateFrom").val();
    
      if (Date.parse(DateToValue) <= Date.parse(DateFromValue)) {
          $("#DateFrom").val(DateToValue)
      }
    
    0 讨论(0)
  • 2020-12-10 04:27

    The Easy Way to Do is

     var start= new Date($('#txtstart').val());
     var end= new Date($('#txtend').val());
                if (start < end) {
    
                }
    
    0 讨论(0)
  • 2020-12-10 04:32

    My Comparison with the current date

        function isPastDate(dateText) {
    // date is dd/mm/yyyy
            var inputDate = dateText.split("/");
            var today = new Date();
            inputDate = new Date(inputDate[2], inputDate[1] - 1, inputDate[0], 0, 0, 0, 0);
            today = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0, 0);
            return inputDate < today;
    };
    
    0 讨论(0)
  • 2020-12-10 04:34

    Use DateJS for parsing your date. http://www.datejs.com/ just include the script in your html.

    0 讨论(0)
  • 2020-12-10 04:37

    you can use below code to parse through the dates, using the millisecond approach (adding milliseconds present in a day) will not work properly for the daylightsaving.

    for ( beginDate= new Date(startDate.getTime()); beginDate.getTime()<=endDate.getTime(); beginDate.setDate(beginDate.getDate() + 1)) {
                dateRangeArray.push(new Date(beginDate.getTime()));
            }
    
    0 讨论(0)
提交回复
热议问题