Jump to content

[SOLVED] date format question


bschultz

Recommended Posts

I have a query that pulls info from the DB.  This code:

 

echo "<a href='/recipes.php?recipe_day=$row[recipe_day]'>".DATE_FORMAT($row[recipe_day],'%M %e, %Y')." "$row[title]"</a><br />"; 

 

doesn't display the DATE_FORMAT part.  As you can see, I need the raw data (column is "date" in the DB) for the link...but want the date to only be formatted for the link.

 

Any ideas why this isn't working?  I should add that it just doesn't display the date in the link...no errors.

 

Thanks.

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

The DATE_FORMAT() function that you are using is a mysql function and is used in your SELECT query.

 

Edit: There is a php DATE_FORMAT function but it operates on a php date object (not just a variable that contains a date), uses a different format string, and is only available in php 5.2 or higher.

since I only need the date formatted in one of the two places it's being used, would I have to assign the formatted date a variable in the select...and use $row[recipe_day] where I don't want it formatted and $newrecipeday where I do want it formatted...or use two fields in the DB?

Now I think I broke it even worse..I get a "no matches" echo from the query

 

$sql = "SELECT *, DATE_FORMAT('recipe_day', '%M %e %Y') as newrecipeday, FROM bitk ORDER BY recipe_day DESC";   	
$rs = mysql_query($sql,$dbc);  
$matches = 0; 
while ($row = mysql_fetch_assoc($rs))  {
$matches++; 

echo "<a href='/recipes.php?recipe_day=$row[recipe_day]'>".$row[newrecipeday]." "$row[title]"</a><br />"; 

}  
if (! $matches) { 
echo ("no matches"); 
}  
echo "<br />";  
?> 

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.