Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

I am currently working on building a baseball website. On one side of the page I want to display information on the next upcoming game. I am using mysql ver. 5.0.45. My table is built as so:

opposingTeam, date, time, score

  • Date is in the mysql date format (yyyy-mm-dd)
  • I have found the datediff(date1,date2) command and tried experimenting with this with no luck

I have tried queries such as:

SELECT *
FROM schedule
WHERE MIN(DATEDIFF(CURDATE(),date))
  • But this gives me an arror because I am using the MIN() function wrong
  • I am still pretty new to mysql and I just can not seem to figure this out
like image 359
Collin Price Avatar asked Sep 03 '25 04:09

Collin Price


1 Answers

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

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

If you want to display all upcoming games use:

SELECT * FROM `schedule` WHERE `date` >= CURDATE() ORDER BY `date`;
like image 127
Dave Forgac Avatar answered Sep 05 '25 00:09

Dave Forgac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!