I'm creating a query its long so I won't post it all but this part in question.
So $dateQuery outputs
When I send the full query with date range I get spurious results, I'm expecting no results at all, but I get many.
Now the weird bit if I echo $dateQuery then copy and paste the output into the query it works as expected. Or if I don't use the date function and do $first = '2012-10-01'; $last = '2012-10-31'; then it also works as expected.
So somehow the date function although its string is somehow different to $first = '2012-10-01';
If I do echo gettype($first); it outputs a string.
I tried:
None Of the above works. Its driving me crazy. If I copy and paste the output it works fine, any ideas why this would be anything other than a normal string. I use the date function all the time without any problems in my queries so not sure why this is happening?
Code:
$first = date('Y-m-d', mktime(0, 0, 0, 10, 1, $y));
$last = date('Y-m-t', mktime(0, 0, 0, 10, 1, $y));
$dateQuery = " ITRAN.IT_DUE >= { d '$first'} AND ITRAN.IT_DUE <= { d '$last'} AND ";
So $dateQuery outputs
Code:
ITRAN.IT_DUE >= { d '2012-10-01'} AND ITRAN.IT_DUE <= { d '2012-10-31'} AND
Now the weird bit if I echo $dateQuery then copy and paste the output into the query it works as expected. Or if I don't use the date function and do $first = '2012-10-01'; $last = '2012-10-31'; then it also works as expected.
So somehow the date function although its string is somehow different to $first = '2012-10-01';
If I do echo gettype($first); it outputs a string.
I tried:
Code:
$first = date('Y-m-d', mktime(0, 0, 0, $i, 1, $y));
$first = (string)$first;
//and
$first = date('Y-m-d', mktime(0, 0, 0, $i, 1, $y));
$first = print_r($first,true);
//and
$first = date('Y-m-d', mktime(0, 0, 0, $i, 1, $y));
$pieces = explode("-", $first); //was a stab in the dark
$first = $pieces[0]."-".$pieces[1]."-".$pieces[2];
//and
$first = date('Y-m-d', mktime(0, 0, 0, $i, 1, $y));
$first = strval($first);
//and
var_dump($first); //tells me its a string.
None Of the above works. Its driving me crazy. If I copy and paste the output it works fine, any ideas why this would be anything other than a normal string. I use the date function all the time without any problems in my queries so not sure why this is happening?