How can I match two dates in JavaScript
? Determine if they are equal, or if one is greater than another. The values I'm getting from inputs
text.
How can I match two dates in JavaScript
? Determine if they are equal, or if one is greater than another. The values I'm getting from inputs
text.
In javascript there is something called Date object. With getTime () you can get the values and compare them with each other Using ===, == !, > , < , etc. For example:
var fechauno = new Date();
var fechados = new Date(fechauno);
var resultado = fechauno.getTime() === fechados.getTime();
The first thing you need to know about dates is that to pass a String to Date you just have to create a Date type object by passing the String of the date as an argument. When you have the Date object you can already get the time with the getTime method of the Date object, and compare it with the getTime of another Date object as in the following example:
if( (new Date('primera fecha').getTime() > new Date('segunda fecha').getTime()))
{
"Hacer algo"
}