Reputation: 4171
Using MySQL
The two fields I need to compare the current date to are: startDate, endDate
I need a query something like this:
SELECT * FROM `{$this->_sPrefix}`
WHERE `profileID` = '{$iProfileId}'
AND CUR_DATE()
BETWEEN `startDate` AND `endDate`
ORDER BY `added` DESC";
This is my new query but I don't know how to do both checks: profileID and the date together.
Upvotes: 0
Views: 1028
Reputation: 50970
You should be able to do that, but you have to use BETWEEN:
WHERE CUR_DATE() BETWEEN `startDate` AND `endDate`
What SQL database are you using?
Edit (in response to edited question, and please don't keep changing the question!):
Your query looks correct, assuming that profileID, startDate, and endDate are all columns in the same table.
Also, if this is a web-facing application, please consider avoiding this kind of dynamic SQL generation as it makes your application open to SQL injection attacks.
Upvotes: 2
Reputation: 135739
...WHERE `startDate` <= CUR_DATE() and `endDate` >= CUR_DATE()
Upvotes: 1