Compare two dates with JavaScript -


Is there less than two dates , less than, and not in the past using Javascript? The value will be coming from the text box ...

Whatever you want will - one For Construction , & lt; , & lt; = or & gt; = .

== , ! = , === , and ! == Operators require you to use date.getTime () as

  var d1 = new date (); Var d2 = New Date (D1); Same = d1.getTime () === d2.getTime (); Var notSame = d1.getTime ()! == d2.getTime ();  

To be clear, checking the parallelism with the data object will not work

  var d1 = new date (); Var d2 = New Date (D1); Console.log (D1 == D2); // Print wrong (wrong!) Console.log (D1 === D2); // print wrong (wrong!) Console.log (d1! = D2); // print right (wrong!) Console.log (D1! == D2); // print right (wrong!) Console.log (d1.getTime () === d2.getTime ()); // print right (correct)  

I suggest that you use some similar type of date entry instead of a drop-down or text box, so that you do not have the input validation hell Find in


Comments