what you need to do is develop better debugging skills
so as a first step place a watch or breakpoint on the function/code reporting problems
Google
then run the code, at the breakpoint step through the code using the F8 key
examine the contents of all variables as you go through to make certain they are what you expect and are valid.
as the error you are reporting is to do with bad SQL and we can't see the contents of your sql you need to find out what is in there.
it could be a malformed date
it could be a missing or invalid parameter
it could be a typo
if you cannot determine what the problem is, then by all means post the actual SQL here