search

Home  >  Q&A  >  body text

Is there a way to automatically update the offset in the query when tijdtot is negative

I have a question. I have a query that calculates how many days until the next Grand Prix event in a list. Then I use the offset, if the event goes to 0 days or negative, I actually want to automatically go to the next positive number. I calculate Timeto between datetime and curdate in a table.

SELECT
    gp_naam, VT1, VT2, VT3, kwalificatie, race, image, CURDATE(),
    DATEDIFF(VT1, CURDATE()) AS Tijdtot
FROM grand prix
ORDER BY Tijdtot ASC
LIMIT 1 OFFSET 1

I've tried everything and I think I need to do something with the WHERE Timeto >0 but it won't accept it and causes an error. Does anyone know how I can solve this problem? Thanks in advance for your help and comments

P粉023326773P粉023326773448 days ago623

reply all(1)I'll reply

  • P粉026665919

    P粉0266659192023-09-13 00:18:43

    You can use a similar method to get the countdown:

    SELECT
        gp_naam, VT1, VT2, VT3, kwalificatie, race, image,
        TIMESTAMPDIFF(DAY, NOW(), VT1) AS days,
        TIMESTAMPDIFF(HOUR, NOW(), VT1) % 24 AS hours,
        TIMESTAMPDIFF(MINUTE, NOW(), VT1) % 60 AS mins
    FROM grand_prix
    WHERE VT1 > NOW()
    ORDER BY VT1 ASC
    LIMIT 1;

    reply
    0
  • Cancelreply