Reputation: 215
I have tried researching but can't figure it out. My SQL table has a column of type "date" which structures the data as YYYY-MM-DD. How do I perform an SQL query to search between two dates?
If I change start - end to 1 - 999999999 then it displays all my data, so I know my query is working. I just can't get it to understand my date values.
<?php
$start = '2015-01-01'
$end = '2015-12-31'
$query = "SELECT * FROM table WHERE (Week BETWEEN $start AND $end)";
?>
Upvotes: 0
Views: 109
Reputation: 38552
You can do it like
$start = '2015-01-01';
$end = '2015-12-31';
$query= "SELECT * FROM table WHERE Week
BETWEEN '$start' AND '$end'";
OR
$query= "SELECT * FROM table WHERE Week
>= '$start' AND Week <= '$end'";
Upvotes: 0
Reputation:
try to change,
$query = "SELECT * FROM table WHERE (Week BETWEEN $start AND $end)";
to
$query = "SELECT * FROM table WHERE Week BETWEEN '$start' AND '$end'";
and the fields $start and $end should be of the type date
Upvotes: 1