mysql - Trying to apply PHP date format -


i trying apply date format mysql. column field type 'date' , formatted in mysql example 2015-03-16, , fields without dates null.

when apply following code, fields dates displayed correctly - 03/16/2015.

however, null fields in mysql displayed in webpage 31/12/69. idea can do?

if(!$rs = mysql_query("select vessel_name, builder, built, listing_price, date_listed, loa, price_original, price_previous, amt_reduced, amt_pct boats")) {     echo "cannot parse query"; } elseif(mysql_num_rows($rs) == 0) {     echo "no records found"; } else {     echo "<table id=\"boatstable\" class=\"bordered\" cellspacing=\"0\">\n";     echo "<thead>\n<tr>";     echo "<th>vessel_name</th>";     echo "<th>builder</th>";     echo "<th>built</th>";     echo "<th>listing price</th>";     echo "<th>date listed</th>";     echo "<th>loa</th>";     echo "<th>original price</th>";     echo "<th>previous price</th>";     echo "<th>amt reduced</th>";     echo "<th>amt pct</th>";     echo "</tr>\n</thead>\n";     while($row = mysql_fetch_array($rs)) {         echo "<tr><td>$row[vessel_name]</td><td>$row[builder]</td><td>$row[built]</td><td>$row[listing_price]</td><td>".date("m/d/y", strtotime($row['date_listed']))."</td><td>$row[loa]</td><td>$row[price_reduced]</td><td>$row[price_previous]</td><td>$row[amt_reduced]</td><td>$row[amt_pct]</td></tr>\n";     }     echo "</table><br />\n"; 

well have identify missing dates , put else out instead, so

while($row = mysql_fetch_array($rs)) {     $fixed_date = $row['date_listed'] == 'null'                    ? 'n/a'                    : date("m/d/y", strtotime($row['date_listed']));     echo "<tr>             <td>$row[vessel_name]</td>             <td>$row[builder]</td>             <td>$row[built]</td>             <td>$row[listing_price]</td>             <td>". $fixed_date ."</td>             <td>$row[loa]</td>             <td>$row[price_reduced]</td>             <td>$row[price_previous]</td>             <td>$row[amt_reduced]</td>             <td>$row[amt_pct]</td>         </tr>\n"; } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -