Jump to content

MySql date format from YYYY-MM-DD to MM-DD-YYYY


Recommended Posts

Hello Everyone


I am working on a website for my favorite hobby. I have created the dynamic pages and they are ready to go. I am having trouble however with the dates. I want all the dates to show up as MM-DD-YYYY. Not sure how to do that with a while loop. I am also trying to figure out how to make the date say "Lost Info" if the date is showing the default.(0000-00-00)


Here is my code so far



$sql = 'SELECT id, l_name, f_name, date_sent, date_return, item_return FROM `ttmautos` WHERE `l_name` LIKE \'a%\' AND `category` LIKE \'baseball\' ORDER BY `date_return` DESC'; 
$link_result = mysql_query($sql, $connection) or die(mysql_error());

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
<link rel="stylesheet" type="text/css" href="../../css/top_nav.css">
<link rel="stylesheet" type="text/css" href="../../css/main_layout.css"/>

<script src="../../scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="../../scripts/top_nav.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Baseball Autographs A</title>
<div id="wrapper">
<?php include('../../includes/page/header.php'); ?>
   	<?php include('../../includes/page/top_nav.php'); ?>
   	<?php include('../../includes/page/left_sidebar_autopages.php'); ?>
   	<?php include('../../includes/page/right_sidebar.php'); ?>
   <div id="content">
            <ul class="list_heading">
               <li class="title">player name</li>
               <li>date sent</li>
               <li>date recievied</li>
               <li class="return">item recievied</li>
            <ul class="list">
		while ($link=mysql_fetch_array($link_result)){
			echo "<li>$link[f_name] $link[l_name]</li>
				  <li class=\"return\"><a href=\"/auto_pages/baseball/baseball-autographs.php?l_name=$link[l_name]&f_name=$link[f_name]\">$link[item_return]</a></li>";

		if($link[date_sent]=="0000-00-00") {
			echo "Lost Info";

		if (!($link = mysql_fetch_array($link_result))) {
			return "Currently our database has no autographs listed for here";
   <!--END content div-->
<!--END wrapper div-->
<?php include('../../includes/page/footer.php'); ?>

Link to comment
Share on other sites

When I run the query in the mysql database. It returns the faults that I am looking for and formats it the proper way. But when I put the code in php code. It does not show me any results.


can you give me an example of what you mean please?

Link to comment
Share on other sites

I figured it out and now I have it working the way that I want. What I ended up doing was changing


$dsent = $link['date_sent'];
$dreturn = link['date_return'];




$dsent = date('m-d-Y', strtotime($link['date_sent']));
$dreturn = date('m-d-Y', strtotime($link['date_return']));


now it works exactly like I want it to

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.