Time interval filter

Hello I'm trying to program so that a msg will be given only from monday to friday between 8 and 15 o'clock.

The passing on with "if" comands in workdays I got it.

Now I do not know how to do that with the time interval.

I've already got the time, but how do I compare these? Can someone help me?
Code is below

Thank you

Best regards,

Agrotar

var weekday = new Date().getDay();
var day;
var time = new Date().getTime();

if(weekday == 1) day = 'Montag';
if(weekday == 2) day = 'Dienstag';
if(weekday == 3) day = 'Mittwoch';
if(weekday == 4) day = 'Donnerstag';
if(weekday == 5) day = 'Freitag';

if (weekday == 1){
    return msg;
}
if (weekday == 2){
   return msg;
}
if (weekday == 3){
    return msg;
}
if (weekday == 4){
    return msg;
}
if (weekday == 5){
    return msg;
}


Maybe something like:

const now = new Date();
const day = now.getDay();
const hour = now.getHours();
if (day >= 1 && day <= 5 && hour >= 8 && hour <= 15) {
   // Code here for time in range
}
1 Like

Thanks mister Kolban,

you give me the Solution of my problem.

I wich you a nice day.

Greetings,

Agrotar