Date Error???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Date Error???

Post 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
";
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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;
}
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post by elinews »

Thanks Kieran Huggins. But it didn't seem to make any difference. This one has really got me stumped.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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
There are 10 types of people in this world, those who understand binary and those who don't
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post 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>";
}
Post Reply