Q:

mysql select query with dates not returning correct records

I have a query that is supposed to pull records from several tables using a join, and filter all of them based on a date range. It seems to be pulling a random group of records  - it doesn't return all the records in the join, which I imagine it would if it were completely ignoring the dates, but the records it does pull don't match the date criteria.
Here's the query; I've tried it two different ways with the same result.
Option 1:
SELECT p.PurchActvtyID, p.PurchAmt, p.CcAuthCode, p.PurchDT,  v.VoucherNbr, 
 a1.name as billName, a1.company as billCompany, a1.address1
  FROM arrc_PurchaseActivity p
LEFT JOIN arrc_Voucher v  ON p.VoucherID = v.VoucherID
LEFT JOIN jos_customers_addresses a1 ON p.AcctID = a1.id
where v.TypeFlag='S'  or v.TypeFlag is null 
and p.PurchDT between '20101201000000' and '20101209235959' order by v.ActivatedDT asc

(In this case, we've programmatically added times to the starting and ending range to ensure we get every record from 12:01 AM on the start date to 11:59 PM on the end date.)
Option 2:
SELECT p.PurchActvtyID, p.PurchAmt, p.CcAuthCode, p.PurchDT,  v.VoucherNbr, 
  a1.name as billName, a1.company as billCompany, a1.address1                 
   FROM arrc_PurchaseActivity p
 LEFT JOIN arrc_Voucher v  ON p.VoucherID = v.VoucherID
 LEFT JOIN jos_customers_addresses a1 ON p.AcctID = a1.id
 where v.TypeFlag='S'  or v.TypeFlag is null 
 and p.PurchDT between '2010-12-01' and '2010-12-09' order by v.ActivatedDT asc

What I'm getting back is records with p.PurchDT equal to 2010-10-28 16:33:13, 2010-11-11 10:37:30, and several others. The good news is it is pulling in all records with dates between the ones indicated in the query; the bad news is it's randomly (from what I can tell) also pulling in other records that don't fit the criteria.
Can anyone point me in the right direction? I could have sworn this code was working several weeks ago, but now it isn't, even though there haven't been any changes to it.

A:

That's probably because you need () in:
 where (v.TypeFlag='S'  or v.TypeFlag is null)

The results with incorrect dates would all have TypeFlags='S', right?
Additionally, if you use dates in the between, you should use the day next to the last that you want, otherwise, the last day would only include records with PurchDT = 2010-12-09 00:00:00 and everything else from that day would be ignored - I guess.

