mdmartiny Posted May 1, 2011 Share Posted May 1, 2011 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 <?php include('../../includes/config.php'); $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"> <head> <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> </head> <body> <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> <ul class="list"> <?php while ($link=mysql_fetch_array($link_result)){ echo "<li>$link[f_name] $link[l_name]</li> <li>$link[date_sent]</li> <li>$link[date_return]</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"; } ?> </ul> </div> <!--END content div--> </div> <!--END wrapper div--> <?php include('../../includes/page/footer.php'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/235252-mysql-date-format-from-yyyy-mm-dd-to-mm-dd-yyyy/ Share on other sites More sharing options...
requinix Posted May 1, 2011 Share Posted May 1, 2011 You can use DATE_FORMAT to change the date in your SQL query. For the default date you can just compare the value with 00-00-0000. Though really, you should be using NULL for those values. Quote Link to comment https://forums.phpfreaks.com/topic/235252-mysql-date-format-from-yyyy-mm-dd-to-mm-dd-yyyy/#findComment-1208929 Share on other sites More sharing options...
mdmartiny Posted May 1, 2011 Author Share Posted May 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235252-mysql-date-format-from-yyyy-mm-dd-to-mm-dd-yyyy/#findComment-1209098 Share on other sites More sharing options...
fugix Posted May 1, 2011 Share Posted May 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235252-mysql-date-format-from-yyyy-mm-dd-to-mm-dd-yyyy/#findComment-1209193 Share on other sites More sharing options...
mdmartiny Posted May 2, 2011 Author Share Posted May 2, 2011 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']; to $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 Quote Link to comment https://forums.phpfreaks.com/topic/235252-mysql-date-format-from-yyyy-mm-dd-to-mm-dd-yyyy/#findComment-1209249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.