I'm currently trying to see if the date value is set to today's date or greater.
var date = document.getElementById("inputDate").value;
var varDate = new Date(date); //dd-mm-YYYY
var today = new Date();
if(varDate >= today) {
//Do something..
alert("Working!");
}
Date format dd-mm-YYYY
The current code above won't work.
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.' );
Among various kind of data validation, validation of date is one. 1. dd/mm/yyyy or dd-mm-yyyy format. 2. mm/dd/yyyy or mm-dd-yyyy format. In the following examples, a JavaScript function is used to check a valid date format against a regular expression.
Checks if a date is after another date. Use the greater than operator (>) to check if the first date comes after the second one.
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.
If you only want to compare Date and not Date-Time then add this line
var today = new Date(); today.setHours(0,0,0,0);
before comparison.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With