Welcome to Geeklog, Anonymous Thursday, April 18 2024 @ 12:20 am EDT

Geeklog Forums

MySQL help: Long date to short date


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!


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


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 12:20 am.

  • 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