Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
Remove times between 2 other ones
app.post('/checkTimes', (req, res) => {
    let date = req.body.date;
    let times = [
        "16:00",
        "16:30",
        "17:00",
        "17:30",
        "18:00",
        "18:30",
        "19:00",
        "19:30",
        "20:00",
        "20:30",
        "21:00",
    ];

    connection.query("SELECT time FROM appointments WHERE date = ?", [date], (err, result) => {
        if(err) throw err;

        let timesToReturn = [];
        // Get all times that are not between start time and end time
        for(let i = 0; i < times.length; i++) {
            let found = false;
            for(let j = 0; j < result.length; j++) {
                if(times[i] == result[j].time) {
                    found = true;
                    break;
                }
            }
            if(!found) timesToReturn.push(times[i]);
        }

        res.status(200).send(timesToReturn);
    });
});

So, I got this. It only checks start time right now, but I want it to remove all times that are between start and end. Not sure how to do that if anyone could help me i'd be much appreciated for example if I got an appointment between 16:00 and 17:30 I want it to remove 16:00, 16:30 and 17:00

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

app.post('/checkTimes', (req, res) => {
    let date = req.body.date;
    let times = [
        "16:00",
        "16:30",
        "17:00",
        "17:30",
        "18:00",
        "18:30",
        "19:00",
        "19:30",
        "20:00",
        "20:30",
        "21:00",
    ];

    connection.query("SELECT time, endTime FROM appointments WHERE date = ?", [date], (err, [result]) => {
        if(err) throw err;

        if(result) {
            let timesToReturn = [...times.slice(0, times.indexOf(result.time)), ...times.slice(times.indexOf(result.endTime))];
            res.status(200).send(timesToReturn);
        } else {
            res.status(200).send(times);
        }
    });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!