alemapo Posted July 6, 2009 Share Posted July 6, 2009 This is a follow up to a previous question. My previous questions was answered by MatthewJ and it worked but now I have another issue. The initial question was formatting data from MySQL type timestamp and set to CURRENT_TIMESTAMP. I wanted format mm-dd-yyyy. MatthewJ's answer to use the following worked. SELECT DATE_FORMAT(yourdatefield, '%m-%d-%Y') FROM yourtable However, in another program which uses sprintf it gives me an error. I am using PHP/Dreamweaver and I'm a newbie. My first sample where it was a straight select worked fine as below: $query_Recordset1 = "SELECT cls_id, DATE_FORMAT(cls_entry_date, '%m-%d-%Y') as display_date, cls_type FROM classifieds"; The new page which Dreamweaver uses sprintf - I assume because now there is a URL variable involved - the DATE_FORMAT gives an error. The code I am trying is: $query_Recordset1 = sprintf("SELECT cls_id, cls_mem_id, DATE_FORMAT(cls_entry_date, '%m-%d-%Y') as display_date, cls_type, cls_item, cls_description, cls_price, cls_contact, cls_email, cls_phone, cls_type_service, cls_lost_found FROM classifieds WHERE cls_type = %s", GetSQLValueString($colname_Recordset1, "text")); I get the following error on the sprintf: Warning: sprintf() [function.sprintf]: Too few arguments in C:\www\vhosts\localhost\_\masterdatesprintf.php on line 48 Do I need to change the syntax of the DATE_FORMAT inside the sprintf? Or will it not work there like it did in the straight select statement? I hope that wasn't confusing. Please let me know if you need more info. THANKS! Pamela Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted July 6, 2009 Share Posted July 6, 2009 date_format is a mysql function it won't work in php. for php you'll need to use date("m-d-Y", strtotime($date)); Quote Link to comment Share on other sites More sharing options...
alemapo Posted July 6, 2009 Author Share Posted July 6, 2009 Thanks! The sprintf was throwing me. It worked! Pamela Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.