Jump to content

[SOLVED] checking if a date from mysql is bigger than 0000-00-00.


Flames

Recommended Posts

in mysql the default for a date field is 0000-00-00, but i want to check if the date is bigger than that and so has therefore been edited.

i tried doing

$sql = "SELECT *,DATE_FORMAT(date, '%D %M %Y') AS date2,DATE_FORMAT(edit_date, '%D %M %Y') AS edit_date2,DATE_FORMAT(edit_date, '%D') AS edit_date4 FROM News WHERE name LIKE '%$news%' ORDER BY id ASC";
$result = mysql_query($sql) or die(mysql_error());
echo "News matching search criteria (news title)";
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Title</th>
<th>Posted by</th>
<th>Posted at</th>
<th>Edited at</th>
</tr>";

while($row2 = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row2['id'] . "</td>";
echo "<td>" . $row2['name'] . "</td>";
echo "<td>" . $row2['poster'] . "</td>";
echo "<td>" . $row2['date2'] . "</td>";
if($row2['edit_date3'] < 1)
{
echo "<td> Hasn't been edited </td>";
}
else
{
echo "<td>" . $row2['edit_date2'] . "</td>";
}
echo "</tr>";
}
echo "</table>";
}

but it always shown hasn't been edited

print_r() is your friend...if it wasn't doing what i was expecting, i would have done:

print_r($row); //Added for debugging
if($row2['edit_date3'] < 1)

 

then it would have dumped out the values and you would have seen the problem

Archived

This topic is now archived and is closed to further replies.

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