Problems with using SQL Between

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bianster
Forum Newbie
Posts: 13
Joined: Sun Feb 08, 2004 3:47 am

Problems with using SQL Between

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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)
Post Reply