[thelist] SQL to select dates before x days

John Corry webshot at members.evolt.org
Wed May 15 20:59:01 CDT 2002

> I don't know what DB you're using, but it sounds like it
> might be a date-formatting thing. I'm an ASP and SQL Server
> guy myself, so this might not be helpful, but you can do it
> DB-side in SQL Server with something like:
> SELECT * FROM events WHERE eventDateTime <= DATEADD(day, 45,
> GetDate())

Thanks, it was a syntax mistake I was overlooking. The correct query
looks like:

$now = date("Y-m-d H:i:s");
// current events table query
$query = "SELECT eventName, DATE_FORMAT(eventDateTime, '%a, %b %e, %Y
%l:%i %p') AS time, eventLoc, eventDesc FROM events where eventDateTime
<= date_add(\"".$now."\", interval 45 day)";


More information about the thelist mailing list