Results 1 to 3 of 3
Thread: gt lt operators in mysql query
Jul 19, 2000, 14:18 #1
the table is library,, branch is one of several nv, bh, gp, etc.
//first i get the current date.
//query the db
$query = "select * from library"
. " where branch='nv'"
//the following line is the problem.
. " and date < $Today"
. " order by date ";
or die ("Cannot execute query");
the lt and gt do not work the way shown in page 54 of MySQL and logically they should. any idea what i am doing wrong?
Jul 19, 2000, 19:00 #2
- Join Date
- Apr 2000
- Melbourne, Australia
- 1 Post(s)
- 0 Thread(s)
The problem is that you aren't putting quotes around your date string. Try the following in MySQL:
mysql> SELECT 2000-07-20;
mysql> SELECT "2000-07-20";
Notice that, in the first case, MySQL treats the expression as an arithmetic operation and subtracts 27 from 2000 to give 1973. In the second case, the quotes tell MySQL that the expression is to be treated as a literal string, and no calculation is performed.
Thus, your line can be fixed by adding quotes around the date value:
. " and date < '$Today'"
Helping Small Business Grow Online!
Jul 19, 2000, 19:33 #3
sometimes i get to tracking on a problem and the obvious goes unobserved.