PHP Date Converter script not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jthermane24
Forum Newbie
Posts: 16
Joined: Wed Feb 17, 2010 8:15 pm
Location: New Jersey

PHP Date Converter script not working

Post by jthermane24 »

I'm trying to write a script that converts a unix timestamp to date time, with php, and displays it along with the title it's corresponding article. Now matter how hard, or how many different combinations, I try I can't get it to work and keep getting prompted with the same Prase Error. Can anyone look at the script and error pasted below and point me in the right direction? Thanks for the help.

Code: Select all

Parse error: syntax error, unexpected T_STRING in /xxxxx/htdocs/RecentNews.php on line 14

Code: Select all

<?php
// Standard functions
require('functions.php');
 
// Connect to the database
database_connect('Admin');
 
// Set up the query and run it
$sql = "SELECT * FROM `cmsarticles` LIMIT 0, 5 ";
$result = mysql_query($sql) or die(mysql_error());
 
// Start echo of list
echo'<ul>';
 
while ($row = mysql_fetch_array($result)) {
    $timestamp = $row['date'];
    $timestamp = date(F d Y,$timestamp);    
    echo'<li><h3>' . $timestamp . '</h3><p><a href="../admin/viewarticle.php?id=' . $row['ID'] . '">' .     $row['title'] . '</a></p></li>';
}
 
echo'</ul>';
    
?>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Date Converter script not working

Post by califdon »

For one thing, you need quotation marks around the pattern part of your date() call:
$timestamp = date('F d Y',$timestamp);

If there are still problems, they may be in the included "functions.php" file, which you haven't shown to us.
User avatar
jthermane24
Forum Newbie
Posts: 16
Joined: Wed Feb 17, 2010 8:15 pm
Location: New Jersey

Re: PHP Date Converter script not working

Post by jthermane24 »

califdon wrote:For one thing, you need quotation marks around the pattern part of your date() call:
$timestamp = date('F d Y',$timestamp);

If there are still problems, they may be in the included "functions.php" file, which you haven't shown to us.
Unbelievable that I missed that, the fix worked, it's always the simple things that you have to look over. Thanks.
Post Reply