Page 1 of 1
Date Error???
Posted: Mon Sep 10, 2007 3:10 pm
by elinews
This is a bit from a code I have been using for a certain website for about a month now. It has been working fine until today I noticed it displayed the else statement for articles that where edited today (September 10th, 2007). I've been playing around with it trying to fix this, and haven't had any success - but I can simply cannot understand why it is doing this. I alos noticed it will repeat this for tomorrow and the day after. Any thoughts? THANKS!
Code: Select all
$query = "SELECT *, DATE_FORMAT(last_edit, '%M %D, %Y') as last_edit FROM database WHERE `page_name` like '$page_name' AND `side` LIKE 'l' AND `position` > 0 ORDER BY `position`";
if ($last_edit > date("F jS, Y", strtotime ("-8 days"))) echo "
Updated $last_edit
"; else echo "
$last_edit
";
Posted: Mon Sep 10, 2007 3:21 pm
by Kieran Huggins
you should be using braces... and semicolons...
Code: Select all
if ($last_edit > date("F jS, Y", strtotime ("-8 days") ) ) {
echo "Updated ".$last_edit;
} else {
echo $last_edit;
}
Posted: Mon Sep 10, 2007 3:56 pm
by elinews
Thanks Kieran Huggins. But it didn't seem to make any difference. This one has really got me stumped.
Posted: Mon Sep 10, 2007 5:50 pm
by VladSun
I tend to do this at DB layer:
Code: Select all
SELECT
*,
DATE_FORMAT(last_edit, '%M %D, %Y') as formatted_last_edit,
IF(`last_edit` > DATE_SUB(CURDATE(),INTERVAL 8 DAY), 1, 0) as edited_in_last8days
FROM `database`
WHERE `page_name` like '$page_name' AND `side` LIKE 'l' AND `position` > 0
ORDER BY `position`";
PS: Database is a keyword - maybe this is your problem with this query... Try to use
mysql_error
Posted: Mon Sep 10, 2007 7:33 pm
by elinews
VladSun wrote:I tend to do this at DB layer:
Code: Select all
SELECT
*,
DATE_FORMAT(last_edit, '%M %D, %Y') as formatted_last_edit,
IF(`last_edit` > DATE_SUB(CURDATE(),INTERVAL 8 DAY), 1, 0) as edited_in_last8days
FROM `database`
WHERE `page_name` like '$page_name' AND `side` LIKE 'l' AND `position` > 0
ORDER BY `position`";
PS: Database is a keyword - maybe this is your problem with this query... Try to use
mysql_error
Thanks - actually I just used "database" rather than the actual db name to make it more clear.
I think your way is excellent. Here's how I just ended up going about it for any out there curious:
Code: Select all
if(strtotime($last_edit)>strtotime('-8 days')){
echo "<div class='last_edit_date'>Updated $last_edit</div>";
}else{
echo "<div class='last_edit_old'>$last_edit</div>";
}