Brandon
Brandon

Reputation: 83

Query for events with a date and time greater than now

all - fairly simple query question that's been hounding me: How do I query for entries with a date and time only greater than now, or when the query is run (page requested)?

I've seen some examples but they aren't good enough for me to modify. Here's my code:

$todaysDate = date("Y-m-d h:i:s");
$params = array('select'=>'*', 'limit'=>3, 'orderby'=>'t.event_StartDate ASC', 't.event_StartDate < "$todaysDate"' );

An example of the variable "t.event_StartDate" outputs "2010-12-10 22:18:42" so I assume that may be how it's saved in the database.

I suspect I'm not building the date correctly or I need to be using a time function I'm not familiar with in MySQL. Help? This is for outputting a series of events with date and time.

Upvotes: 2

Views: 1074

Answers (2)

Cloudson
Cloudson

Reputation: 65

t.event_StartDate > NOW() don't will returns nothing? a date higher of now lol. I'm confused.

Upvotes: 0

ajreal
ajreal

Reputation: 47321

I think you reverse the use <, it should be >

try

SELECT ... WHERE t.event_StartDate>NOW();
/* you don't even need to set $todaysDate */

Upvotes: 1

Related Questions