Welcome to Geeklog Tuesday, July 23 2019 @ 08:06 pm EDT

Geeklog Forums

MySQL help: Long date to short date


nuccio

Anonymous
determined
Hi all,

I have placed this piece of code on my front page, to show the 5 most recent stories posted on my homepage:

<?
$numStories = 5;
$result = mysql_query("SELECT sid, date, title FROM gl_stories ORDER BY `date` DESC LIMIT $numStories&quotWink or die(mysql_error());
if (mysql_num_rows($result)) {
while ($qry = mysql_fetch_array($result)) {
echo " <a href="http://www.martinhover.dk/article.php/$qry[sid]">$qry[date] - $qry[title]</a><br> n";
} ; }
?>

The code produces a link that looks something like this:
2005-09-17 20:29:18 - First week in Barcelona

Can anyone help me change the date format into the following: 2005/09/17?

Thank you very much!

ted

Anonymous
check this function in the php man--strftime()

nuccio

Anonymous
Thank you. I couldn't make that work, but found a way to use the function str_replace() to deliver the result I wanted:

str_replace('-','/',substr($qry['date'],0,10)), which produces the format 2005/09/17.

All times are EDT. The time is now 08:06 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content