Page 1 of 1

Problems with using SQL Between

Posted: Tue Aug 03, 2004 9:40 pm
by bianster
I have a SQL query as the one below =>

Code: Select all

<?php
		$query = "select ID, source, finalPayment, salesPerson1 from Invoice where salesPerson1 > 1 and finalPayment != 0 and finalPaymentDate between $month and $nextMonth";


?>
What happens is that the query returns ALL the records that fulfill "salesPerson1 > 1 and finalPayment != 0" but the "finalPaymentDate between $month and $nextMonth" is not being applied at all.

finalPaymentDate is being stored as a timestamp number in the database

Posted: Wed Aug 04, 2004 2:57 am
by JAM
You don't state, but is $month and $nextMonth converted into timestamp's as well?

Verify using the longer way of writing it...

Code: Select all

... (finalPaymentDate  <= $month AND $nextMonth <= finalPaymentDate)