Ejemplo 1: comparar fechas en js
var date1 = new Date('December 25, 2017 01:30:00');
var date2 = new Date('June 18, 2016 02:30:00');
//best to use .getTime() to compare dates
if(date1.getTime() === date2.getTime()){
//same date
}
if(date1.getTime() > date2.getTime()){
//date 1 is newer
}
Ejemplo 2: comparar fechas en javascript
var date1 = new Date('December 25, 2017 01:30:00');
var date2 = new Date('June 18, 2016 02:30:00');
//best to use .getTime() to compare dates
if(date1.getTime() === date2.getTime()){
//same date
}
if(date1.getTime() > date2.getTime()){
//date 1 is newer
}
Ejemplo 3: comparar fecha javascript
// solution is convert date to time by getTime()
start = startDate.getTime();
end = endDate.getTime();
current = date.getTime();
if (start <= current && current <= end) {
// do something here
}
Ejemplo 4: fechas de comparación de JavaScript
let d1 = new Date();
let d2 = new Date();
// can use >, <, <=, <=
d1 > d2
d1 >= d2
// == won't work so can use this:
(d1 >= d2) && (d2 >= d1)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)