How does one generally check if a random date is at least one day (24hrs) in the past with momentjs?
Something like:
const today = moment()
const isAtLeastADayAgo = today.subtract(dateToCheck) > 1 // ??
You can simply use isBefore
function isADayAgo(input){
let yesterday = moment().subtract(1, 'd');
return input.isBefore(yesterday);
}
const isAtLeastADayAgo = isADayAgo(moment());
console.log(isAtLeastADayAgo);
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
Or you can use diff
limiting granularity to days:
const today = moment();
const dateToCheck = moment().subtract(3, 'd');
const isAtLeastADayAgo = today.diff(dateToCheck, 'd') > 1;
console.log(isAtLeastADayAgo);
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With