'Quickbooks Online API query using variable for date
I am using QBO's API to query various tables using QBO's 'dataService' in their SDK and storing the results in MySQL. I have a table in the db that will store the date of the last successful query to limit the number of records returned.
My query is $qboTableExtract = $dataService->Query("Select * from $qboTable where MetaData.LastUpdatedTime > $qboLastUpdate STARTPOSITION $i MAXRESULTS $end");
$qboLastUpdate is read from a DATE field in MySQL and currently holds "2022-01-01". When I run the query and substitute the single quoted date, i.e. "MetaData.LastUpdatedTime > '2022-01-01' STARTPOSITION" in place of the variable, the query returns correct results. Running with the variable results in no records returned.
I've tried various combinations of single and double quotes on the string and the variable, using MySQL's STR_TO_DATE($qboLastUpdate, %Y-%m-%d), various DATE formatting attempts... no joy. I cannot find a way to format the string that works...
Thank you for looking at this.
Solution 1:[1]
Found the answer on QBO forum... the variable needs to be single quoted within the outer string, i.e. " ' . $qboLastUpdate . ' ".
@Sammitch was right on target!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | startingout |
