const date1 = '25/02/1985';
const date2 = '26/02/1985';
// input 28/10/2018
// input DD/MM/YYYY
export const convertToDate = (dateSting) => {
const [day, month, year] = dateSting.split("/");
return new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
}
console.log(convertToDate(date1) > convertToDate(date2))
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)
let myDate = new Date("January 13, 2021 12:00:00");
let yourDate = new Date("January 13, 2021 15:00:00");
if (myDate < yourDate) {
console.log("myDate is less than yourDate"); // will be printed
}
if (myDate > yourDate) {
console.log("myDate is greater than yourDate");
}
const d1 = new Date("Mon Jan 3 2022 16:38:58 GMT+0530 (India Standard Time)")
const d2 = new Date("2022-01-03T18:30:00Z")
console.log(d1)
console.log(d2)
if (d1 < d2) console.log("Date 1 is earlier than d2")
// To find hh:mm:ss difference for the same day we can do this.
console.log(new Date(d2-d1).toISOString().substr(11, 8))