Comparing date part only without comparing time in JavaScript

后端 未结 22 1671
春和景丽
春和景丽 2020-11-22 10:59

What is wrong with the code below?

Maybe it would be simpler to just compare date and not time. I am not sure how to do this either, and I searched, but I couldn\'t

22条回答
  •  耶瑟儿~
    2020-11-22 11:44

    This is the way I do it:

    var myDate  = new Date($('input[name=frequency_start]').val()).setHours(0,0,0,0);
    var today   = new Date().setHours(0,0,0,0);
    if(today>myDate){
        jAlert('Please Enter a date in the future','Date Start Error', function(){
            $('input[name=frequency_start]').focus().select();
        });
    }
    

提交回复
热议问题