31

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.

Mattlinux1
  • 657
  • 2
  • 11
  • 23
  • please explain what values you want to compare - `today` is misnamed - thats more like `now` including time, not just the date. – Daniel A. White May 27 '16 at 14:18

1 Answers1

45

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.

gurvinder372
  • 64,240
  • 8
  • 67
  • 88