Re: Select where date is in period

From: Date: Thu, 22 Mar 2001 13:43:00 +0000
Subject: Re: Select where date is in period
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-7699@lists.php.net to get a copy of this message
"boclair" <boclair@bigpond.net.au> wrote in message news:005101c0b2d2$4e6b3920$94c32dcb@qld.bigpond.net.au... | | ----- Original Message ----- | From: boclair <boclair@bigpond.net.au> | To: <php-db@lists.php.net> | Sent: Thursday, March 22, 2001 10:45 PM | Subject: Re: [PHP-DB] Select where date is in period | | | > | > ___Morris___ | > | > The database has a table of equipments with date fields for | > date_online and date_offline. | > | > The requirement is to find which equipments were available on a date | > specified by the user, this being a variable created by the user. | > | > My attempts at scripting for the condition where the date_online <= | > 'specified variable' and the date_offline => 'specified variable' | > totally fail for syntax says mySQL (and possibly for method) | > | > ___Richard___ | > | > Have you checked at the BETWEEN (x and y) clause? | > | > e.g. | > | > SELECT * FROM table WHERE searchdate BETWEEN (date_online AND | > date_offline) | > | > Not tested this on MySQL, but the above is perfectly legal SQL92. | > | > ___Morris_____ | > | > Thanks for that. I searched the Manual, yet again and could not | find | > this or like syntax. I tried it though and got | > Warning: Supplied argument is not a valid MySQL result resource. | > | > My attempt, one of many, | > | > $result = mysql_query("select * from plant.eqpt where date_online <= | > $checkdate AND where date_offline => $checkdate order by type, | > size"); | > | > generated the same warning. | | ________ | | Please check this solution for syntax and method. MySQL didn't give | errors or warnings and results were as required. | | $result = mysql_query("select * from plant.eqpt where date_online <= | $checkdate && $checkdate <= date_offline order by type, size"); | | or can use AND in lieu of && | | or can place where conditions in brackets as | | where (date_online <= $checkdate && $checkdate <= date_offline) Sorry. Careless as usual. The variable $checkdate was enclosed in single quotes as $result = mysql_query("select * from plant.eqpt where date_online <= '$checkdate' && '$checkdate' <= date_offline order by type, size"); Tim Morris

« previous php.db (#7699) next »