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

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.

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