I'm new to Node-Red; struggling to learn code that may be applied in a (Function) node. I've written the following which tests to see if todays date falls between November 15th of the current year and January 31 of the following year. It's working okay however I think there may be a better way: less variables to test at the IF statement. Something like IF TODAY() is between START_DATE and END_DATE where November 15, CURRENT_YEAR and January 31, NEXT_YEAR are represented respectively by the above noted variables.
I've tried several ways of writing the statement but each fails to give appropriate results. Would someone be kind enough to a) write the code or b) provide a few hints that would help me out?
//####################################################
//# Operate switch if date is between Nov 15 and Jan 15
//####################################################
let today = new Date();
let dd = today.getDate();
let mm = today.getMonth()+1; //January is 0!
if ((mm == 11 && dd >= 15) || mm == 12 || (mm == 1 && dd <= 31)) {
return [null, msg];
} else {
return [msg, null];
}
Regards, Robert