Eusthace Eusthace - 18 days ago 10
TypeScript Question

Check if date is greater than current date at 17:30

I have a date and a time parameters and I would like to check if that date/time is greater than the current date at 17:30.

I hope we could find a way using moment js. Is it possible?

I am trying this:

let d = moment(new Date()).set({hour:17,minute:30});
let t = moment(myDate).set({hour:paramHour,minute:paramMinute});

if ( t.isAfter(d) ) {
console.log('true');
}


Thank you.

Answer

You probably don't need moment here. Something like this should work fine:

var now = new Date;
var cutoff = new Date;
cutoff.setHours(17);
cutoff.setMinutes(0);
cutoff.setSeconds(0);
cutoff.setMilliseconds(0);

if (now >= cutoff) {
    // Date is past 17:30
}