Sorry, I tried Chat-GPT and the code it gives me looks good - in theory - but I am getting an error.
const startDate = new Date('2024-9-17'); // Replace with your start date
const now = new Date();
const msPerDay = 1000 * 60 * 60 * 24;
const msPerWeek = msPerDay * 7;
const interval = 4 * msPerWeek; // 4 weeks in milliseconds
// Calculate the difference in milliseconds
const diff = now - startDate;
// Check if the difference is a multiple of 4 weeks
if (diff >= 0 && diff % interval < msPerDay) { // Check if within the day
//msg.payload = `Message generated for the event on: ${now.toISOString()}`;
msg.payload = "Recharge phone tomorrow";
return msg; // Allow the message to pass
}
return null; // Do not send a message
What I see:
I understand what it is saying, but can't see the problem.
const now = new_date()
sets now
.
And startDate
....
It is declared/defined.
So how do I get rid of the error?
Thanks.