Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql query : date_format and sprintf()

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

like image 544
user695575 Avatar asked Apr 29 '11 17:04

user695575


People also ask

What is Date_format in MySQL?

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)

How do I change the default date format in MySQL?

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().

How do I get the current date in MySQL workbench?

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.


1 Answers

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"));
like image 185
Parris Varney Avatar answered Sep 23 '22 00:09

Parris Varney