So what’s the solution? You have to “comment-out” the % that aren’t part of your sprintf() substitution. You can do this by putting another % in front of the ‘%’ symbols in the DATE_FORMAT() function. This deems them as a literal percent-sign instead of the start of another sprintf() “variable”.
<?php
// build our sql string.
$sql
=
"SELECT DATE_FORMAT( %%b %%M %%d %%Y, some_date_field ) as myDate FROM table WHERE field=%d"
;
$sqlf
= sprintf(
$sql
,
$somevalue
);
$db
->query(
$sqlf
);
?>