Re: php/mySQL time comparison

From: Date: Fri, 14 Mar 2003 14:44:53 +0000
Subject: Re: php/mySQL time comparison
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139715@lists.php.net to get a copy of this message
On Friday 14 March 2003 22:33, Brad Wright wrote: > I want to pull all data out of a mysql table that falls between two dates > (a start-time and end-time). > > I use PHP to allow the user to specify the time interval, creating 2 > variables > 'startTime' and 'endTime'. These are formatted thus: 2002-02-25 00:00:00 > (YYYY-MM-DD HH:mm:ss). > > I then use the syntax: > $query = "select * from Job_TB where teamNo = $teamNo AND startTime >= > $timeFrom AND endTime <= $timeTo"; Try enclosing the dates with single-quotes (they are strings). > $result = mysql_query($query,$db) or die ("somethings wrong"); Try using mysql_error() to see _what_ went wrong instead of just reporting that _something_ went wrong. Also consider using BETWEEN (check mysql manual). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* The onset and the waning of love make themselves felt in the uneasiness experienced at being alone together. -- Jean de la Bruyere */

« previous php.general (#139715) next »