0

I have a query that needs to return records where the ShipDate is between a range of dates. The following query works:

$query = "SELECT ECCustomerOrder.ShipDate, 
ECCustomers.Customer, 
ECCustomerOrder.PO, 
ECCustomerOrder.TotalCases, 
ECCustomerOrder.order_number
FROM ECCustomerOrder INNER JOIN ECCustomers ON ECCustomerOrder.ID = ECCustomers.ID
WHERE ECCustomerOrder.ShipDate >= $todayMinus";

$todayMinus is a php variable set earlier in the script that takes the current date and subtracts 15 days. What I can't get to work is the following:

$query = "SELECT ECCustomerOrder.ShipDate, 
ECCustomers.Customer, 
ECCustomerOrder.PO, 
ECCustomerOrder.TotalCases, 
ECCustomerOrder.order_number
FROM ECCustomerOrder INNER JOIN ECCustomers ON ECCustomerOrder.ID = ECCustomers.ID
WHERE ECCustomerOrder.ShipDate BETWEEN $todayMinus AND $todayPlus";

What is the proper syntax for this SQL query to return the records between the ShipDates of $todayMinus and $todayPlus?

1
  • Is this MySQL?, do you need to include results for today?, why is it not working? Commented Feb 19, 2013 at 19:13

1 Answer 1

3

assuming you're using plain dates, you'll have to quote them.

e.g.

ShipDate BETWEEN 2013-01-01 AND 2013-02-19

is incorrect, because 2013-01-01 is a substraction, you're actually doing

ShipDate BETWEEN 2011 AND 1992

try

ShipDate BETWEEN '$todayMinus' AND '$todayPlus'
Sign up to request clarification or add additional context in comments.

1 Comment

That's all it took, Marc. Thanks for the tip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.