0

i have a question. I have a query that calculates how many days it is until the next grand_prix event in the list. I then work with offset and I actually want to automatically go to the next positive number if the event becomes 0 days or a negative number. i calculate the Timeto in the table between datetime and curdate.

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 already tried everything and I think I need to do something with WHERE Timeto >0 but it won't accept it and result in an error. does anyone know how i can solve this? thanks in advance for your help and input

  • You cannot use expressions for the LIMIT args in MySQL. Please do not post images of your data! Update your question with a markdown or ascii table of your data and your expected result. You are probably looking for: `WHERE VT1 > NOW()` or `WHERE VT1 > CURDATE()` depending on when you want it to change which ones are being returned. – user1191247 Feb 23 '23 at 20:02
  • Oh sorry. I will remove the images. I added them so it was clear what i was looking for with the query... i tried your input and you are really a hero... exactly what i was lookong for. Working like a charm – Marcel Kuijper Feb 23 '23 at 20:15

1 Answers1

0

You could use something like this to get your 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;
user1191247
  • 10,808
  • 2
  • 22
  • 32