How to Check Given Date is Greater than Today using JavaScript

Date validation is very useful when you want to restrict the user to provide a future date. You can easily compare the date with current date using JavaScript. This tutorial will show you how to check if selected date is greater than today using JavaScript.

JavaScript Date Object provides a simple way to instantiate a date. The following example code checks whether given date is greater than current date or today using with new Date() in JavaScript.

var GivenDate = '2018-02-22';
var CurrentDate = new Date();
GivenDate = new Date(GivenDate);

if(GivenDate > CurrentDate){
    alert('Given date is greater than the current date.');
}else{
    alert('Given date is not greater than the current date.');
}

Leave a reply

keyboard_double_arrow_up