I want to use sprintf() along with date_format in a MySQL query.
Here is query:
mysql_select_db($database_exdb, $expdb);
$query_eventeditrs = sprintf("SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'), timeofevent, location, details, presenter, bio FROM events WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
I am getting error that :
“Warning: sprintf() [fun
ction.sprintf]: Too few arguments. Query was Empty”
Plz help
DATE_FORMAT() function in MySQL is used to format a specified date as given format value i.e., a date will be given and this function will format that date as specified format parameters. Syntax : DATE_FORMAT(date, format)
Change the curdate() (current date) format in MySQL The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().
MySQL NOW() Function The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.
You have to escape the date format string with extra %'s, try this:
sprintf("SELECT eventid, groupid, title,
DATE_FORMAT(dateofevent, '%%W, %%M %%d, %%Y'),
ti meofevent, location, details, presenter, bio
FROM events
WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With