Comparing date part only without comparing time in JavaScript

后端 未结 22 1674
春和景丽
春和景丽 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:36

    After reading this question quite same time after it is posted I have decided to post another solution, as I didn't find it that quite satisfactory, at least to my needs:

    I have used something like this:

    var currentDate= new Date().setHours(0,0,0,0);
    
    var startDay = new Date(currentDate - 86400000 * 2);
    var finalDay = new Date(currentDate + 86400000 * 2);
    

    In that way I could have used the dates in the format I wanted for processing afterwards. But this was only for my need, but I have decided to post it anyway, maybe it will help someone

提交回复
热议问题