Jump to content

[SOLVED] Date Format Question


alemapo

Recommended Posts

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/164989-solved-date-format-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.