I think the problem is with the way Drupal substitutes arguments / named parameters. See the second parameter for db_query.
You should really refactor your code to use a db_select. https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_query/7
https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7
To add the STR_TO_DATE functionality, use the AddExpression functionality. https://api.drupal.org/api/drupal/includes!database!select.inc/function/SelectQuery%3A%3AaddExpression/7
Using these two will definitely solve your problem. Good luck.