-1

Okay so am using this structure in my SQL database:

id  |  title  |   date_start   |   date_end|  time_start   |   time_end   |   location   |

I am wanting to sort data from that table, but only the upcoming dates or dates that are currently occurring.

I've used the following query in php:

$query = mysql_query("SELECT * FROM events3 ORDER BY date_start DESC LIMIT 5");

Then after the query I fetched the results, then echoed them as so:

http://pastebin.com/5wS7npsr

That would display the only two dates in the database as:

ID:   2
Title:   New Years Eve
Date Start:   2012-12-31 - 2012-12-31
Time Frame:   12:00:00 - 12:00:00
Location:   Earth
Description:   The last day of 2012.


ID:   1
Title:   Christmas Day
Date Start:   2012-12-25 - 2012-12-25
Time Frame:   12:00:00 - 12:00:00
Location:   Earth
Description:   Merry Christmas!!

But I want it to expire after the date has occurred and only show the next upcoming ones.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Harrison Howard
  • 153
  • 3
  • 4
  • 14

1 Answers1

0

As mentioned in comments, there is a similar post here: Datetime equal or greater than today in MySQL

Ultimately, after some back and forth, the resulting query for your specific implementation:

SELECT * FROM events3 WHERE date_start >= CURDATE() ORDER BY date_start LIMIT 5;
Community
  • 1
  • 1
Mike Purcell
  • 19,847
  • 10
  • 52
  • 89