How do you get the next upcoming date from the table?

I am currently working on a baseball site. On one side of the page I want to display information about the next upcoming game. I am using mysql ver. 5.0.45. My table is built like this:

counteringTeam, date, time, rating

  • The date is in mysql date format (yyyy-mm-dd)
  • I found the dateiff command (date1, date2) and tried to experiment with this with no luck

I have tried queries like:

SELECT *
FROM schedule
WHERE MIN(DATEDIFF(CURDATE(),date))
  • But this gives me a message because I am using the function incorrectly MIN()
  • I'm still pretty new to mysql and I just can't figure it out.
+3
source share
5 answers

If you want to display the following game (including today), you can use the following:

SELECT * FROM `schedule` WHERE `date` >= CURDATE() ORDER BY `date` LIMIT 1;

, :

SELECT * FROM `schedule` WHERE `date` >= CURDATE() ORDER BY `date`;
+12

, :

SELECT * FROM `schedule` WHERE `date` > NOW() ORDER BY `date` LIMIT 1

LIMIT 1 , , ( LIMIT 1, )

0

:

select top 1 * from schedule where date>=CURDATE() order by date
0

, .

, , , "".

, , , / - .

, , , CURDATE(). ( .)

0
source

try SELECT max(day) FROM schedule

This gives the highest date from the table.

To get the next day, use:

SELECT  
DATE_ADD(max(day),INTERVAL 1 DAY)
FROM schedule 

(I used "day" for your date field)

0
source

Source: https://habr.com/ru/post/1706309/


All Articles