I'm trying to get the current date (day, hour, minute, second) and put it in an if() statement to compare it with the date entered. But how am I able to get the date and ask for it in code?
This is what I got so far:
bot.on("ready", () => {
var today = new Date();
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
var time = today.getHours() + ":" + today.getMinutes();
var currentdate = date + time
var endDate = new Date('2021-01-21T14:00:00')
if (endDate = currentdate) {
console.log('The time has come..')
} else {
console.log('The time is coming soon..')
}
})
you can use 'moment.js' like this :
const moment = require("moment");
getDifferenceInYear(date_1, date_2) {
return moment(date_1).diff(moment(date_2), "years");
}
getDifferenceInDay(date_1, date_2) {
return moment(date_1).diff(moment(date_2), "days");
}
getDifferenceInHour(date_1, date_2) {
return moment(date_1).diff(moment(date_2), "hour");
}
getDifferenceInSecond(date_1, date_2) {
return moment(date_1).diff(moment(date_2), "second");
}
isNowBetween(startDate, endDate) {
return moment(new Date()).isBetween(startDate, endDate);
}
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