Pierre Kircher
Pierre Kircher

Reputation: 19

SQL query for selecting events that occurs at a certain date and time

I figure my head around for the best possible query to get the actual event with ! query

This is what I have :

$date = date( 'Y-m-d' );
$time = date( 'Gi' ); 

datasource : http://screencast.com/t/ODthUUpfR

$sql = "SELECT * FROM events WHERE startdate = '" . $date . "' AND stopdate >= '" . $date . "' ORDER BY stopdate ASC";

The problem I have is if the actual date is 2011-09-15 and the time is 600 (06:00)

The event would be still TeamA but with the above query it would return TeamB.

Upvotes: 0

Views: 165

Answers (1)

dqhendricks
dqhendricks

Reputation: 19251

first, you should have these stored in two DATETIME fields... you are making it way more complicated by storing this in 4 fields.

Then you should do a query more like

WHERE $datetime BETWEEN start_datetime AND end_datetime

Upvotes: 2

Related Questions