typescript dates compare code example
Example 1: compare dates in js
var date1 = new Date('December 25, 2017 01:30:00');
var date2 = new Date('June 18, 2016 02:30:00');
if(date1.getTime() === date2.getTime()){
}
if(date1.getTime() > date2.getTime()){
}
Example 2: date compare in js
var x = new Date('2013-05-23');
var y = new Date('2013-05-23');
x < y; => false
x > y; => false
x === y; => false, oops!
+x <= +y; => true
+x >= +y; => true
+x === +y; => true
Example 3: how to compare two date in typescript
for(let k = 0; k < this.bookingDetailsArrayRealObject.length; k++){
let dateCheckOut = this.bookingDetailsArrayRealObject[k].package.chackout;
let dateToBeCheckOut = new Date(dateCheckOut);
let today = new Date();
if(this.bookingDetailsArrayRealObject[k].status){
if(dateToBeCheckOut < today){
this.bookingIdsToBeUpdated.push(this.bookingDetailsArrayRealObject[k]._id);
window.alert('true');
console.log(today.toDateString());
console.log(dateToBeCheckOut.toDateString());
console.log(this.bookingDetailsArrayRealObject[k]);
}
}
}