Skip to main content
Participant
September 29, 2009
Answered

DATE_FORMAT in filtered recordset

  • September 29, 2009
  • 1 reply
  • 554 views

I am having trouble formatting the date with php/MySQL in a filtered recordset. I am looking at the tutorial on http://forums.adobe.com/thread/450108 which shows how to do it. I've gotten it to work for a regular query but it sends back errors when I try to insert it into a filtered recordset. Here is the code I am trying but it's not working.

$blog_id = "-1";

if (isset($_GET['blog_id'])) {

  $blog_id = $_GET['blog_id'];

}

$query_blog_comments = sprintf("SELECT blog_id, blog, comment, display, DATE_FORMAT(date, '%W, %M %e, %Y') AS date_formatted FROM blog_comment WHERE blog_id = %s AND display = 1 ORDER BY blog_id ASC", GetSQLValueString($blog_id, "text"));

Please tell me how to format a date for a filtered recordset. Thanks!

This topic has been closed for replies.
Correct answer DwFAQ

Heya,

Try this code:

$blog_id = "-1";
if (isset($_GET['blog_id'])) {
  $blog_id = $_GET['blog_id'];
}

$query_blog_comments = sprintf("SELECT 
blog_id, blog, comment, display, 
DATE_FORMAT(date, '%%W, %%M %%e, %%Y') 
AS date_formatted 
FROM blog_comment 
WHERE blog_id = %s 
AND display = 1 
ORDER BY blog_id ASC", 
GetSQLValueString($blog_id, "text"));

The difference is an extra '%' placed in each date variable of DATE_FORMAT

1 reply

DwFAQ
DwFAQCorrect answer
Participating Frequently
September 30, 2009

Heya,

Try this code:

$blog_id = "-1";
if (isset($_GET['blog_id'])) {
  $blog_id = $_GET['blog_id'];
}

$query_blog_comments = sprintf("SELECT 
blog_id, blog, comment, display, 
DATE_FORMAT(date, '%%W, %%M %%e, %%Y') 
AS date_formatted 
FROM blog_comment 
WHERE blog_id = %s 
AND display = 1 
ORDER BY blog_id ASC", 
GetSQLValueString($blog_id, "text"));

The difference is an extra '%' placed in each date variable of DATE_FORMAT

Participant
September 30, 2009

It works! Thank you so much.