Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date formatting not working

Posted on 2012-04-05
1
Medium Priority
?
218 Views
Last Modified: 2012-04-24
I have date formatting for my blog working fine on the initial page using...

mysql_select_db($database_GrandRoofing, $GrandRoofing);
$query_Recordset1 = "SELECT id, intro, title, date_format(`eventdate`,'%D %M %Y') as `formattedDate`, copy, images, category FROM news ORDER BY eventdate DESC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $GrandRoofing) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

Open in new window


However, when I try to use it on a results page I get a 'Query was empty' error'

This code works fine without formatting..

$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_GrandRoofing, $GrandRoofing);
$query_Recordset1 = sprintf("SELECT id, intro, title, eventdate, copy, images, category FROM news WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $GrandRoofing) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

Open in new window


but when I try to format it like the first bit of code the error occurs...

$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_GrandRoofing, $GrandRoofing);
$query_Recordset1 = sprintf("SELECT id, intro, title, date_format(`eventdate`,'%D %M %Y') as `formattedDate`, copy, images, category FROM news WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $GrandRoofing) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

Open in new window



Any ideas why the formatting is causing this error?
0
Comment
Question by:BrighteyesDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 37812447
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

No really good ideas what might be wrong but I can tell you the easy way to handle this sort of thing.  Store all the dates in ISO-8601 format (MySQL DATE or DATETIME column type).  And use the ISO-8601 representations for all internal purposes.  In PHP, this is date('c').  Then when you want to reformat a date for presentation, use strtotime() and date() to turn the ISO format into a nice, human-readable format.  If you want day, month and year, it might look something like this...
$query_Recordset1 = "SELECT id, intro, title, eventdate, copy, images, category FROM news ORDER BY eventdate DESC";
$Recordset1 = mysql_query($query_Recordset1) or die("FAIL: $query_Recordset1<br/>" . mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$formattedDate = date('j M Y', strtotime($row_Recordset1['eventdate']));

Open in new window

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question